File file = new File("./.project");
System.out.println(file.getAbsolutePath());
System.out.println(file.getCanonicalPath());
if(file.exists()){
String line = new Reader(file.getAbsolutePath()).readAll();
System.out.println(line);
}
file = new File("../test.txt");
System.out.println(file.getAbsolutePath());
System.out.println(file.getCanonicalPath());
if(file.exists()){
String line = new Reader(file.getAbsolutePath()).readAll();
System.out.println(line);
}在eclipse 中新建一个工程。跑完上一个程序就知道咋回事了
运行结果
E:\workspaces\MyEclipse_9\openfire\.\.project E:\workspaces\MyEclipse_9\openfire\.project <?xml version="1.0" encoding="UTF-8"?><projectDescription> 。。。。</natures></projectDescription> E:\workspaces\MyEclipse_9\openfire\..\test.txt E:\workspaces\MyEclipse_9\test.txt dfdfdf E:\workspaces\MyEclipse_9\openfire
本文通过示例代码展示了如何在Java中操作文件、获取文件路径并进行基本的文件读取。通过运行示例代码,可以清晰地了解Java文件路径解析及文件读取的基本流程。
2119

被折叠的 条评论
为什么被折叠?



