[英]how to set the file path in netbeans within the same build directory?
我想为我要读取的文件设置路径,而不必指定根目录或整个路径。 像这样: 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目录中,但是它也不起作用。 它显示此消息:
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
将您的文件放在BankAccountGUI
目录(项目的根目录)中。 然后尝试像这样访问文件:
File file = new File("Text01.txt");
注意:-您的文件应该与src
文件夹处于同一级别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.