private void monthlyInput() throws IOException {
File inFile = new File(Environment.getExternalStorageDirectory ().getAbsolutePath(), "S050213.txt");
String data = inFile.getAbsolutePath();
TextView testData = (TextView) findViewById(R.id.textView1);
testData.setText(data);
FileInputStream fInStream = new FileInputStream(inFile);
BufferedReader myReader = new BufferedReader(new InputStreamReader(fInStream));
String data2 = myReader.readLine();
TextView testData2 = (TextView) findViewById(R.id.textView2);
testData2.setText(data2);
myReader.close();
}
我知道这是找到文件,因为数据输出正确的文件路径,但data2似乎是空的。我最好的猜测是,它是没有找到该文件在Buffered Reader not reading
FileInputStream fInStream = new FileInputStream(inFile);
我想知道我错了,或者如果我甚至接近我应该在哪里。
它抛出异常吗?如果没有,你的文件可能存在,但在读取前检查文件是否存在 – nullptr 2013-05-05 05:38:49
。if(inFile.exists())'然后只做东西 – Pragnani 2013-05-05 05:40:40
如果有异常检查权限 – 2013-05-05 05:40:44