-1
我正在創建一個設置文件,如果它不存在,將會創建該文件。我已經嘗試創建一個文件,但它也沒有工作。以下代碼用於創建新的txt文件。未創建新的txt文件
try {
PrintWriter SettFile = new PrintWriter(new BufferedWriter(new FileWriter("Settings.txt")));
SettFile.println("170 000 150");
SettFile.println("114 000 106");
SettFile.close();
} catch (IOException e) {
System.out.println("An error Accured Loading The Settings");
}
System.out.println("Setting File Succesfuly Created");
以下代碼用於搜索值。
try{
BufferedReader file = new BufferedReader(new InputStreamReader(new FileInputStream("Settings")));
System.out.println("Reading Values from \"Settings.txt\"...");
int i = 0;
String TempSettingValue;
while((TempSettingValue = file.readLine()) != null){
SettingValue[i] = TempSettingValue;
System.out.println("Value " + (i + 1) + ": " + SettingValue[i]);
i++;
}
file.close();
}
catch(IOException e){
System.out.println("Something went wrong loading the Settings...");
}
發生了什麼讓你覺得它不起作用? –
它沒有出現在文件系統中,並且程序說它以後不能加載設置 –
@ F.hanhansson運行此代碼我沒有收到任何錯誤,並且該文件是用您放入的內容創建的它! – cunniemm