我使用下面的代碼從我的SD卡上讀取txt文件,但是如何將它顯示爲文本視圖?如何讀取.txt文件並將其顯示爲Android中的TextView?
try{
File f = new File(Environment.getExternalStorageDirectory()+"/filename.txt");
FileInputStream fileIS = new FileInputStream(f);
BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
String readString = new String();
//just reading each line and pass it on the debugger
while((readString = buf.readLine())!= null){
Log.d("line: ", readString);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
它給我在線路錯誤時(返回text.toString();)?? – Leon 2012-01-01 20:57:03
它仍然是一樣的? – Leon 2012-01-01 21:02:28
我檢查了它,但它仍然給我一個錯誤(返回text.toString();) – Leon 2012-01-01 21:07:27