Re: [問題] 讀取文字檔(/raw;/assets;/res)
※ 引述《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
12/30 19:49, 1F
推
01/01 09:23, , 2F
01/01 09:23, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 6 之 6 篇):