Re: [問題] 讀取文字檔(/raw;/assets;/res)
請問大大,
我將檔案*.txt放置sd卡後~
在debug模式下執行到
FileOutputStream outputStream = new FileOutputStream(file);
就會跳到catch中..
請問是否還有其他細節須注意的呢?謝謝
※ 引述《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);
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.130.55.241
→
12/29 12:27, , 1F
12/29 12:27, 1F
→
12/29 12:27, , 2F
12/29 12:27, 2F
→
12/29 12:28, , 3F
12/29 12:28, 3F
→
12/29 12:29, , 4F
12/29 12:29, 4F
→
12/29 12:30, , 5F
12/29 12:30, 5F
→
12/29 12:31, , 6F
12/29 12:31, 6F
推
12/29 12:56, , 7F
12/29 12:56, 7F
討論串 (同標題文章)