Re: [問題] 讀取文字檔(/raw;/assets;/res)

看板AndroidDev作者 (別理我)時間12年前 (2011/12/30 15:48), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串6/6 (看更多)
※ 引述《sweet00914 (別理我)》之銘言: : ※ 引述《givemepass (〆)》之銘言: : : 把你的檔案放在assets裡面 : : 我假設你的檔案叫做 my_text_file.txt : : 然後我複製一份存到sdcard下面/sdcard/text_file.txt : : 就可以拿這個來讀取 : : public class TestRandomFileAccessActivity extends Activity { : : /** Called when the activity is first created. */ : : @Override : : public void onCreate(Bundle savedInstanceState) { : : super.onCreate(savedInstanceState); : : setContentView(R.layout.main); : : //先取得資產管理員 : : AssetManager assetManager = this.getApplicationContext().getAssets(); : : try { : : //用資產管理員打開文字檔 變成串流 : : InputStream inputStream = assetManager.open("my_text_file.txt"); : : byte[] b = new byte[1024]; : : int len = -1; : : File file = new File("/sdcard/text_file.txt"); : : FileOutputStream outputStream = new FileOutputStream(file); 後來我使用 RandomAccessFile random = new RandomAccessFile( File.createTempFile( "test" , "tmp" ), "rwd" ); 來建立檔案。這樣子一來,等待程式結束後,新增的暫存檔也會被刪除。 而不會永遠停留在sd卡上~ 不知道大家有何建議?0.0 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.130.55.241

12/30 19:49, , 1F
不知道你的出發點是什麼 我自己覺得是能不IO就盡量不IO
12/30 19:49, 1F

01/01 09:23, , 2F
http://ppt.cc/DMwr 這篇有效率比較 只是資料很舊...
01/01 09:23, 2F
文章代碼(AID): #1E_MpEN2 (AndroidDev)
討論串 (同標題文章)
文章代碼(AID): #1E_MpEN2 (AndroidDev)