【问题标题】:how to set the file path in netbeans within the same build directory?如何在同一构建目录中的netbeans中设置文件路径?
【发布时间】:2013-04-08 11:19:06
【问题描述】:

我想为我要读取的文件设置路径,而不必指定根目录或整个路径。 像这样:File file = new File("Text01.txt");Path file = Paths.get("Accounts.txt"); 而不是:Path file = Paths.get("C:\\Users\\B_HITMAN\\Documents\\NetBeansProjects\\BankAccountGUI\\src\\bankaccountgui\\Accounts.txt"); 我什至尝试将文件放在 netbeans 的构建目录中,但它也不起作用。它显示了这条消息:

Exception in thread "main" java.io.FileNotFoundException: Text01.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at assignment01.Assignment01.main(Assignment01.java:19)
Java Result: 1

【问题讨论】:

    标签: java file netbeans path stream


    【解决方案1】:

    将您的文件放在BankAccountGUI 目录(项目的根目录)中。然后尝试像这样访问文件:-

    File file = new File("Text01.txt");
    

    注意:-您的文件应与src 文件夹处于同一级别。

    【讨论】:

    • 我把它放在根目录下,但是没有用。同级是什么意思?
    • 在根目录中,您的文件应该存在,甚至src 文件夹也应该只存在于该路径中。到时候就可以了。
    • 文件和 src 存在,还有一些其他文件和文件夹也像 build 文件夹。
    猜你喜欢
    • 2011-01-25
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 2019-05-12
    • 2013-02-27
    • 2020-01-13
    相关资源
    最近更新 更多