2015-11-05 91 views

回答

3

把文件中assets/(例如,在一個典型的Android Studio項目app/src/main/assets/)。然後在AssetManager上使用open()以獲得該內容的InputStream。您可以通過撥打getAssets()Activity或其他Context獲得AssetManager

+0

謝謝最佳路徑!很有幫助! – Mumfordwiz

0

移動文件到存儲卡,並添加,而不是「file.txt的」

File sdcard = Environment.getExternalStorageDirectory(); 

//Get the text file 
File file = new File(sdcard,"file.txt"); 

//Read text from file 
StringBuilder text = new StringBuilder(); 

try { 
    BufferedReader br = new BufferedReader(new FileReader(file)); 
    String line; 

     while ((line = br.readLine()) != null) { 
      text.append(line); 
      text.append('\n'); 
     } 

    br.close(); 
    }catch (IOException e) { 
//You'll need to add proper error handling here 
} 

//Find the view by its id 
TextView tv = (TextView)findViewById(R.id.text_view); 

//Set the text 
tv.setText(text); 

它例如,如果你想閱讀的文本

相關問題