創建文件的源碼(程序的一部分):
public void newParamFile()
{try{
paramFile.createNewFile();
oneInput=new FileInputStream(paramFile);
progressFile.load(oneInput);
oneInput.close();
oneOutput=new FileOutputStream(paramFile);
for(int i=0;i<threadNum;i++)
{
progressFile.setProperty("thread["+i+"]",Long.toString(0));
}
progressFile.store(oneOutput,null);
}catch(Exception e){System.out.println("文件更新失敗");e.printStackTrace();}
finally{
try{
oneOutput.close();
}
catch(Exception es){System.out.println("流關閉失敗");es.printStackTrace();}
}
}
但關閉整個程序,該文件爲空:原因是我在另一個方法中操作該文件的時候(查詢)對輸出與輸入流沒有妥善處理