关于文件路径

来源:互联网 发布:软件外包的优缺点 编辑:程序博客网 时间:2024/05/02 04:57

工程的目录结构如下:

myproject

               tt

                                   et

                                                       a.dtdt

                                   mat.java

 

如果要正确处理文件a.dtdt,得到文件有如下几种方式:

FileInputStream in = new FileInputStream(".//tt//et//a.dtdt");

此时.代表了工程的根目录:myproject


mat.class.getResource("/").getPath()

/ 代表了工程的根目录:myproject

 

mat.class.getResource(".").getPath()

 

.代表了当前目录:myproject.tt