Reputation: 372
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");
or Path file = Paths.get("Accounts.txt");
instead of : 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. 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
Upvotes: 0
Views: 4403
Reputation: 45060
Place your file in the BankAccountGUI
directory(project's root directory). 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.
Upvotes: 1