我们的示例代码
EditText txtData = (EditText) findViewById(R.id.txtData);
Button btnReadSDFile = (Button) findViewById(R.id.btnReadSDFile);
btnReadSDFile.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// write on SD card file data in the text box
try {
//Read a file from SDCard to TextBox(EditText)
File myFile = new File("/mnt/sdcard/config_data.med");
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
String aDataRow = "";
String aBuffer = "";
while ((aDataRow = myReader.readLine()) != null) {
aBuffer += aDataRow + "\n";
}
txtData.setText(aBuffer);
myReader.close();
String s = txtData.getText().toString();
Log.e("txtData",s);
}catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
我们的原始文件内容
Welcome
To
All
我们的日志结果截图
为什么我们的内容在这里崩溃?我们如何解决它?