2013-08-22 78 views
-2

這是我在下面的代碼,我試圖寫入文件中的數據。但值不成功寫入文件也沒有拋出任何異常。所以我覺得它可能是一個文件權限問題。如果是這種情況,那麼將拋出異常。文件寫入問題

public void setPrice(PriceDetails priceDetails)throws IOException { 
    priceoutputStream = new FileOutputStream(cacheFile); 
    String priceDetailsString = priceDetails.toString(); 
    String valueString = priceDetailsString.substring(priceDetailsString.indexOf("=")+1); 
    priceDetailsProperties.setProperty(formatPLU(priceDetails.getPlu()),valueString)??; 
    priceDetailsProperties.store(priceoutputStream,null); 
    priceoutputStream.close(); 
} 

你能幫我嗎?

+2

我們可以。但我們不會 - 因爲我們需要**異常跟蹤**來幫助... – ppeterka

+0

似乎應該有一個'priceoutputStream.write()'在那裏。 –

+0

什麼'priceDetailsProperties.store(priceoutputStream,null);'做什麼? – hasanovh

回答

0
  • 我認爲,我們可以簡單地做到這一點使用另一種方法,因爲有沒有二進制數據寫入或讀取,我們可以使用Reader and Writer with Buffers.

請嘗試以下代碼,將其寫入文件:

File f = new File("Path"); 
FileWriter fw = new FileWriter(f); 
BufferedWriter bw = new BufferedWriter(fw); 

bw.write("Your Data"); 

bw.close();