如何在同一个构建目录中的netbeans中设置文件路径?

时间:2013-04-08 11:19:07

标签: java file netbeans path stream

我想设置我要读取的文件的路径,而不必指定根目录或整个路径。 像这样: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

1 个答案:

答案 0 :(得分:1)

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

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

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