getAbsolutePath getCanonicalPath 区别以及 当前目录、上级目录 用法

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


你可能感兴趣的:(eclipse,MyEclipse,String,File,encoding)