2013-04-08 4 views
0

루트 디렉토리 또는 전체 경로를 지정하지 않고 읽을 파일 경로를 설정하고 싶습니다. 은 다음과 같습니다 : 또는 Path file = Paths.get("Accounts.txt"); 대신 : Path file = Paths.get("C:\\Users\\B_HITMAN\\Documents\\NetBeansProjects\\BankAccountGUI\\src\\bankaccountgui\\Accounts.txt"); 파일을 netbeans의 빌드 디렉토리에 넣으려고했으나 작동하지 않았습니다. 이 쇼의 메시지 :동일한 빌드 디렉토리 내의 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

루트 디렉토리에 넣었지만 작동하지 않았습니다. 같은 수준에서 무엇을 의미합니까? –

+1

루트에는 파일이 있어야하며'src' 폴더도 그 경로에만 있어야합니다. 그때 작동합니다. – SudoRahul

+0

파일과 src가 있고 다른 일부 파일과 폴더도 빌드 폴더와 같습니다. –

관련 문제