问题描述
所以我意外收到FileNotFoundException异常。正如你所看到的,前不久我打电话的FileReader,我称之为的FileInputStream工作正常。我试图把的FileReader在自己的try / catch子句,但得到相同的结果。我已经烧毁大部分不必要的线路从该块我的问题。 (最后我呼吁LineNumberReader为好,但我删除它从块,因为我还没有得到那么远。)
So I'm unexpectedly receiving a FileNotFoundException. As you can see, shortly before I call the FileReader, I call FileInputStream which works fine. I've tried putting the FileReader in its own Try/Catch clause, but receive the same result. I've gutted most of the lines unnecessary to my question from this block. (Ultimately I call LineNumberReader as well, though I removed it from the block because I'm not even getting that far.)
String FILENAME = "file.txt";
try {
byte[] buffer = new byte[128];
String toStr = new String();
TextView view = (TextView)findViewById(R.id.textview);
FileInputStream fis = openFileInput(FILENAME); /////File is found successfully here/////
fis.read(buffer);
fis.close();
toStr = new String(buffer);
view.append(toStr);
FileReader fr = new FileReader(FILENAME); /////FileNotFoundExceptionThrownHere/////
/////do stuff here/////
fr.close();
}
catch (FileNotFoundException e) {
TextView view = (TextView)findViewById(R.id.textview);
view.append("file not found!");
}
catch (IOException e) {
TextView view = (TextView)findViewById(R.id.textview);
view.append("IO error!");
}
此外,请记住在回答这个我还是有点新手,当涉及到Java的时候。我有一对夫妇的其他语言的经验,但Java是一个有点不同的品种怪物给我的。任何帮助将是巨大的AP preciated!
Also, please keep in mind when answering that I'm still somewhat of a novice when it comes to java. I have experience in a couple other languages but java is a bit of a different breed of monster to me. Any help would be tremendously appreciated!
推荐答案
openFileInput()
和新的FileReader()
不采取同样的参数。
openFileInput()
and new FileReader()
do not take the same parameter.
openFileInput(file.txt的)
等同于新的FileReader(新文件(getFilesDir(),file.txt的))
。
这篇关于安卓的FileReader意外抛出FileNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!