我在/ res/raw /文件夹(/res/raw/textfile.txt)中有一个资源文件,我试图从我的Android应用程序中读取进行处理.
public static void main(String[] args) {
File file = new File("res/raw/textfile.txt");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
while (dis.available() != 0) {
// Do something with file
Log.d("GAME", dis.readLine());
}
fis.close();
bis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了不同的路径语法但总是得到java.io.FileNotFoundException错误.如何访问/res/raw/textfile.txt进行处理?是File file = new File("res/raw/textfile.txt"); Android中的错误方法?
*答案: …