이진 파일 내에 데이터를 저장하려고합니다. 존재하지 않으면 폴더를 생성해야합니다. 파일이 존재하지 않으면 생성해야합니다.내 이진 파일을 저장하기위한 상대 경로를 사용하여 경로를 찾을 수 없습니다.
public Account(int accountid, String name, String lastname, double balance, AccountState state) {
this.name = name;
this.lastname = lastname;
this.accountID = accountid;
this.balance = balance;
this.state = state;
try {
accountfile = new File("./Clients/" + lastname + "/" + name + "/" + "BalanceInfo " + accountid + ".ACC");
if(!accountfile.exists()) {
accountfile.createNewFile();
}
fos = new FileOutputStream(accountfile);
oos = new ObjectOutputStream(fos);
oos.writeObject("balance: " + balance);
oos.writeObject("state: " + state.toString().toLowerCase());
} catch(IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
System.out.println("Account sucessfully Created");
}
그러나, 조금 혼란하는 중 다음과 같은 오류를 내가 파일을 생성하지 않습니다를
The system cannot find the path specified
Account sucessfully Created
java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at dinges.Account.<init>(Account.java:44)
at dinges.Main.main(Main.java:10)
를 생성합니다.
'.' - 현재 작업 디렉토리의 상대 경로는 시작점 (IDE, 박쥐, 더블 클릭)에 따라 다르므로 권장하지 않습니다. 'System.getProperty ("user.home") + "/ ..."'등을 사용하십시오. –
@JoopEggen 나는 그것을 사용 하겠지만, runnable jar 파일로 내보낼 경우 jar 파일을 저장하는 폴더가 생성되지 않을까요? 그런 식으로 사용하는 것이 더 쉬운 것처럼 보입니다. –
예, 병을 두 번 클릭하기 만하면됩니다. 아마 내가 비난을 받았을거야. 내 연습은 사용자에게 프롬프트하는 것입니다. –