2016-02-07 198 views
0

我目前有這個問題「File.creteNewFile()被忽略」。 好的,當拍照時,圖片將在圖像切換器中顯示,因此當我拍照並保存時,在拍攝另一張照片後它不會出現在圖像切換器中,則之前的圖片將出現在圖像切換器。 例如,當我拍攝了一張James的照片並保存後,它沒有出現在圖像切換器中,當我拍攝了Simon的照片後,James的照片出現在圖像切換器中,但是Simon沒有,並且拍攝下一張照片那麼Simon圖片將出現在圖像切換器中。File.createNewFile被忽略

public void Save() { 
    try { 
     File f = new File(mPath + "faces.txt"); 
     f.createNewFile(); <-- this is where the method is ignored 
     BufferedWriter bw = new BufferedWriter(new FileWriter(f)); 
     Iterator<label> Ilabel = thelist.iterator(); 
     while (Ilabel.hasNext()) { 
      label l = Ilabel.next(); 
      bw.write(l.thelabel + "," + l.num); 
      bw.newLine(); 
     } 
     bw.close(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     Log.e("error", e.getMessage() + " " + e.getCause()); 
     e.printStackTrace(); 
    } 
} 

我是新與Android,但我希望你們能幫助我:d

乾杯, 在此先感謝:d

回答

0

你結束以.txt文件的路徑,但它是一個圖像不是嗎?我不知道這是否會導致你的問題,但它應該可能是固定的。

0

不使用createNewFile()methos 使用此方法創建文件:

public void Save(){ 
      try 
      { 
       File root = new File(mPath); 
       if (!root.exists()) { 
        root.mkdirs(); 
       } 
       File gpxfile = new File(root, "faces.txt"); 
       FileWriter writer = new FileWriter(gpxfile); 
       writer.append(sBody); 
       writer.flush(); 
       writer.close(); 
       Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show(); 
      } 
      catch(IOException e) 
      { 
       e.printStackTrace(); 
       importError = e.getMessage(); 
       iError(); 
      } 
     } 
+0

喜劍:d是什麼sBody – bo2

+0

數據你想要像JSON或文本或其他東西寫入文件 –

0

檢驗createNewFile是說「File.createNewFile()的結果被忽略」,因爲布爾結果沒有分配到任何變量,所以它忽略

如果你

boolean sucess = file.createNewFile()消息消失:)

獎金,從文檔:

返回true,如果指定的文件不存在,並已成功 創建,假,如果指定的文件已經存在