看板 AndroidDev 關於我們 聯絡資訊
※ 引述《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
KeySabre:不知道你的出發點是什麼 我自己覺得是能不IO就盡量不IO 12/30 19:49
KeySabre:http://ppt.cc/DMwr 這篇有效率比較 只是資料很舊... 01/01 09:23