Android 无法打开文本文件
我有一个字典的文本文件,我想用EditText值匹配单词。但是我得到以下错误java.io.FileNotFoundException:/Test/res/raw/Test.txt:open failed:enoont没有这样的文件或目录 这就是我到目前为止所做的Android 无法打开文本文件,android,eclipse,Android,Eclipse,我有一个字典的文本文件,我想用EditText值匹配单词。但是我得到以下错误java.io.FileNotFoundException:/Test/res/raw/Test.txt:open failed:enoont没有这样的文件或目录 这就是我到目前为止所做的 public void show(View view) throws IOException { File file = new File("/Test/res/raw/test.txt"); if (!file.e
public void show(View view) throws IOException
{
File file = new File("/Test/res/raw/test.txt");
if (!file.exists())
{
helloTxt1.setText("empty");
}
try
{
FileInputStream in = new FileInputStream(file);
int len = 0;
byte[] data1 = new byte[1024];
while ( -1 != (len = in.read(data1)) )
{
if(new String(data1, 0, len).contains(edittxt.getText().toString()))
{
helloTxt1.setText("1");
}
else
{
helloTxt1.setText("0");
}
}
} catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
提前感谢。您需要使用输入流来打开和读取文件 InputStream InputStream=context.getAssets.opentest.txt;并使用阅读器 或
鉴于您已在res文件夹中创建了一个原始文件夹,请从“活动”中调用以下getResources.openRawResourcesmyResourceName。如果文件位于外部存储器上,则应将“读取外部存储器”权限添加到清单中。这是否有帮助?不要使用硬编码路径!: