Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.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
Java FileNotFoundException:Enoont…但是,但是,但是我有一个文件_Java_Android_Filenotfoundexception - Fatal编程技术网

Java FileNotFoundException:Enoont…但是,但是,但是我有一个文件

Java FileNotFoundException:Enoont…但是,但是,但是我有一个文件,java,android,filenotfoundexception,Java,Android,Filenotfoundexception,我使用下面的try/catch尝试将一个管道分隔的文本文件解析为一个数组(每一行都是这样的:spanishword | englishword | spanishword.mp3),用于flashcard应用程序。很简单,但我是个十足的傻瓜。下面是我拼凑的内容,它导致了FileNotFoundException 文件为res/raw/first100mostcomon.txt。我喜欢解决问题,并不是真的有兴趣得到一个解决方案,但一个比“文件未找到”更好的提示将不胜感激 我认为String str

我使用下面的try/catch尝试将一个管道分隔的文本文件解析为一个数组(每一行都是这样的:spanishword | englishword | spanishword.mp3),用于flashcard应用程序。很简单,但我是个十足的傻瓜。下面是我拼凑的内容,它导致了
FileNotFoundException

文件为res/raw/first100mostcomon.txt。我喜欢解决问题,并不是真的有兴趣得到一个解决方案,但一个比“文件未找到”更好的提示将不胜感激

我认为
String strFile=“R.raw.first100mostcomon”是命名它的正确方式;是这样吗

try 
{
    String strFile = "R.raw.first100mostcommon";

    //create BufferedReader to read pipe-separated variable file

    BufferedReader br = new BufferedReader( new FileReader(strFile));
    String strLine = "";
    StringTokenizer st = null;

    int row = 0; 
    int col = 0;

    //read pipe-separated variable file line by line

    while( (strLine = br.readLine()) != null)
    {
        //break pipe-separated variable line using "|"
        st = new StringTokenizer(strLine, "|");

        while(st.hasMoreTokens())
        {
            //store pipe-separated variable values
            stWords[row][col] = st.nextToken();
            col++;
        }
        row++;                                   
        //reset token number
        col = 0;                          
    }     
}
catch(Exception e)
{
    text.setText("Exception while reading csv file: " + e);

}  
该文件为res/raw/first100mostcomon.txt

那不是一个文件。这是一种原始资源。它作为文件存在于开发计算机上。它存在于设备上APK(ZIP存档)中的一个条目中

要以
res/raw/first100mostcomon.txt
的形式访问存储在开发机器上的原始资源,请在任何
上下文上调用
getResources().openrawsource(R.raw.first100mostcomon)
,例如
活动。这将返回一个
InputStream
,您可以使用它读取内容

该文件为res/raw/first100mostcomon.txt

那不是一个文件。这是一种原始资源。它作为文件存在于开发计算机上。它存在于设备上APK(ZIP存档)中的一个条目中


要以
res/raw/first100mostcomon.txt
的形式访问存储在开发机器上的原始资源,请在任何
上下文上调用
getResources().openrawsource(R.raw.first100mostcomon)
,例如
活动。这将返回一个
InputStream
,您可以使用它来读取内容。

logcat会更好;-)除此之外,请参阅我的解决方案comingsoon®-编辑:无解决方案:请参阅您应该使用正确的文件分隔符。类似于
/
而不是
strFile
中的
。当前编译器将其视为完整的文件名,而不是
filepath
。因此,它很可能在
根目录下查找,而该文件不可用,从而导致
FileNotFoundException
您的文件是否与
文件位于同一目录下除此之外,请参阅我的解决方案comingsoon®-编辑:无解决方案:请参阅您应该使用正确的文件分隔符。类似于
/
而不是
strFile
中的
。当前编译器将其视为完整的文件名,而不是
filepath
。因此,它很可能在
根目录下查找,而该文件不可用,从而导致
FileNotFoundException
您的文件是否与
.class
文件位于同一目录下?