the test.xml file is in the files folder, which is in the app folder
when calling the method below, 1 2 3 is displayed in the log, after which an error occurs: File not found: /data/user/0/com.example.myapplication/files/test.xml: open failed: ENOENT (No such file or directory)
method :
protected Document buildDoc(Context context, String fileName) throws Exception{
Document doc = null;
try {
File file = new File(context.getFilesDir(), "test.xml");
Log.d("tag", "1");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
Log.d("tag", "2");
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Log.d("tag", "3");
doc = dBuilder.parse(file);
Log.d("tag", "4");
} catch (FileNotFoundException e) {
Log.e("error", "File not found: " + e.getMessage());
throw e;
} catch (Exception e) {
throw e;
}
return doc;
}
I just can’t understand why and how to fix the error
I cleared the cache and rebooted the studio, but the error does not go away
тук тук тук Пук Пук пук is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.