[問題] 連續QR Code生成txt檔問題

看板AndroidDev作者 (WHY)時間8年前 (2016/05/19 20:14), 8年前編輯推噓1(102)
留言3則, 3人參與, 最新討論串1/1
我現在有個可以連續解碼QR Code的程式 以及一個連續播放QR Code的程式 但是解碼的速度跟不上編碼速度 所以會有一些遺漏 我想生成一個txt檔 把有成功生成的部分製成一個txt檔 以下是那部分的程式碼 public void onCodeScanned(String data) { txv1.setText(String.valueOf(data)); Toast.makeText(MainActivity.this, data,Toast.LENGTH_LONG).show(); try { File file = new File(getExternalFilesDir (Environment.DIRECTORY_DOWNLOADS), "QR Code.txt"); FileOutputStream fos = new FileOutputStream(file); fos.write(data.getBytes()); fos.close(); } catch (IOException e) {} } 但是生成出來的txt檔,只會有最後一個解碼出來的內容(中間其它的都沒有) 請問要如何改呢? 感激~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.123.115.137 ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1463660050.A.EA3.html

05/19 23:04, , 1F
輸出到固定檔案,不是會一直被覆蓋嗎?
05/19 23:04, 1F

05/20 07:33, , 2F
分別寫檔或append,new FileOutputStream(file,true)
05/20 07:33, 2F

05/20 13:23, , 3F
感激 了解了
05/20 13:23, 3F
boolean append=ture; FileOutputStream fos = new FileOutputStream(file,append) 就行了 ; ※ 編輯: puppyulove (140.123.115.137), 05/20/2016 13:26:35
文章代碼(AID): #1NFQuIwZ (AndroidDev)