【问题标题】:What is correct relative path in my project?我的项目中正确的相对路径是什么?
【发布时间】:2014-04-12 18:59:29
【问题描述】:

我需要在 java 中指定 images/tabIcon.gif 的相对路径。

我在课堂 FileViewerManager 中,我需要创建具有 images/tabIcon.gif 相对路径的新文件。

我的代码是:

File file = new File("./images/tabIcon.gif");

我的项目结构是:

src/model/FileViewerManager

src/images/tabIcon.gif

我的代码不起作用,因为 file.exists 返回 false。

【问题讨论】:

    标签: java file path


    【解决方案1】:

    试试这个(我假设你的项目结构中的 FileViewerManager 是一个文件):

    File file = new File("../images/tabIcon.gif");
    

    如果是文件夹,则需要上一个附加目录:

    File file = new File("../../images/tabIcon.gif");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-16
      • 1970-01-01
      • 2011-04-23
      • 2015-01-10
      • 2011-09-24
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多