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

来源:互联网 发布:文件下载 java 编辑:程序博客网 时间:2024/05/28 17:05
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\.\.projectE:\workspaces\MyEclipse_9\openfire\.project<?xml version="1.0" encoding="UTF-8"?><projectDescription>。。。。</natures></projectDescription>E:\workspaces\MyEclipse_9\openfire\..\test.txtE:\workspaces\MyEclipse_9\test.txtdfdfdfE:\workspaces\MyEclipse_9\openfire


原创粉丝点击