看板 AndroidDev 關於我們 聯絡資訊
感謝各為板友的幫忙 問題已解 來回一下自己的文給後人爬 ============================================================= Android Data Storage 的方法有五種 http://developer.android.com/guide/topics/data/data-storage.html 若你英文不好 這裡有中文版 http://charles-song.blogspot.com/2010/11/data-storage-in-android.html 我是使用 Internal Storage =========================創立檔案並寫入=============================== String FILENAME = "Text"; //看你創立的file要叫什麼名稱 String string = "hello world!"; //你想寫入的字串 deleteFile("hello_file"); //如果你想刪除某個file 就用delete //使用 openFileOutput 取得 FileOutputStream FileOutputStream fos = null; try { fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } try { fos.write(string.getBytes()); //寫入string } catch (IOException e){ e.printStackTrace(); } try { fos.close(); } catch (IOException e) { e.printStackTrace(); } ================================讀取檔案內容============================ FileInputStream fis; try { fis = openFileInput(FILENAME); byte[] input = new byte[fis.available()]; while (fis.read(input) != -1) { textview.setText(new String(input)); //我是將取出來的字串用textview顯示 } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } ========================================================================= 以上 如有錯誤請指證 謝謝收看 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.227.122.153
nowar100:解決後分享 推一個 01/20 05:48
a1234957:推解決辦法 01/20 07:49
qrtt1:解決後分享. 推!!! (如果讀取+更新用 AsyncTask 會更好) 01/20 07:57
樓上你沒推阿~~XD 話說 你是在給我新作業嗎? 又是一個沒聽過的東西哪QAQ
qrtt1:呵,俺又不是你老師。只是個良心的建議orz 01/20 15:18
那你給點方向 我來去研究看看好了XD ※ 編輯: nonebelieve 來自: 61.227.122.153 (01/20 15:37)
BlueRyo:有學到有推~~ 01/20 18:23
coronach:方向 => http://tinyurl.com/2ep4fev 01/20 21:28
webb566:太棒了!! 我正需要這個!! 大推大推!!!^^ 04/10 20:51