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