[英]how to set the file path in netbeans within the same build directory?
I want to set the path for my file that i'm going to read without having to specify the root directories or the whole path. 我想为我要读取的文件设置路径,而不必指定根目录或整个路径。 like this : File file = new File("Text01.txt");
像这样: File file = new File("Text01.txt");
or Path file = Paths.get("Accounts.txt");
或Path file = Paths.get("Accounts.txt");
instead of : Path file = Paths.get("C:\\\\Users\\\\B_HITMAN\\\\Documents\\\\NetBeansProjects\\\\BankAccountGUI\\\\src\\\\bankaccountgui\\\\Accounts.txt");
而不是: Path file = Paths.get("C:\\\\Users\\\\B_HITMAN\\\\Documents\\\\NetBeansProjects\\\\BankAccountGUI\\\\src\\\\bankaccountgui\\\\Accounts.txt");
I even tried to put the file inside the build directory of netbeans, but it didn't work either. 我什至试图将文件放在netbeans的build目录中,但是它也不起作用。 it show's this message : 它显示此消息:
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
Place your file in the BankAccountGUI
directory(project's root directory). 将您的文件放在BankAccountGUI
目录(项目的根目录)中。 And then try to access the file like this:- 然后尝试像这样访问文件:
File file = new File("Text01.txt");
Note:- Your file should be at the same level as the src
folder. 注意:-您的文件应该与src
文件夹处于同一级别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.