2013-04-08 49 views
0

我想为我要读取的文件设置路径,而无需指定根目录或整个路径。 这样的: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的构建目录中,但它也没有工作。它展示的这条消息:如何在同一个build目录下的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

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

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

注: -您的文件应在同一水平src文件夹。

+0

我把它放在根目录下,但它没有工作。你在同一层面上的意思是什么? – 2013-04-08 11:32:13

+1

在根目录中,你的文件应该存在,甚至'src'文件夹也只能出现在那个路径中。它会工作。 – SudoRahul 2013-04-08 11:33:31

+0

文件和src都存在,并且其他一些文件和文件夹也与构建文件夹一样。 – 2013-04-08 11:35:46

相关问题