Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:FileReader意外引发FileNotFoundException_Android_Filenotfoundexception_Filereader - Fatal编程技术网

Android:FileReader意外引发FileNotFoundException

Android:FileReader意外引发FileNotFoundException,android,filenotfoundexception,filereader,Android,Filenotfoundexception,Filereader,因此,我意外地收到一个FileNotFoundException。正如您所看到的,在调用FileReader之前不久,我调用了FileInputStream,它工作得很好。我已经尝试将FileReader放在它自己的Try/Catch子句中,但收到了相同的结果。我已经删掉了这一块中我的问题不需要的大部分行。(最终我也调用了LineNumberReader,尽管我将其从块中删除了,因为我甚至没有走那么远。) 另外,在回答这个问题时请记住,对于java,我还是个新手。我有一些其他语言的经验,但jav

因此,我意外地收到一个FileNotFoundException。正如您所看到的,在调用FileReader之前不久,我调用了FileInputStream,它工作得很好。我已经尝试将FileReader放在它自己的Try/Catch子句中,但收到了相同的结果。我已经删掉了这一块中我的问题不需要的大部分行。(最终我也调用了LineNumberReader,尽管我将其从块中删除了,因为我甚至没有走那么远。)

另外,在回答这个问题时请记住,对于java,我还是个新手。我有一些其他语言的经验,但java对我来说是一个不同种类的怪物。任何帮助都将不胜感激

openFileInput()
newfilereader()
不接受相同的参数

openFileInput(“file.txt”)
相当于
newfilereader(新文件(getfiledir(),“file.txt”)

openFileInput()
newfilereader()
不采用相同的参数


openFileInput(“file.txt”)
相当于
newfilereader(新文件(getfiledir(),“file.txt”)

非常感谢您,我为这个愚蠢的问题道歉。我还在努力适应这种语法。非常感谢,我为这个愚蠢的问题道歉。我仍在努力适应这种语法。
        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!");
            }