I get this error when trying to generate some files on the internal drive. Below is an example of printing
03-27 01:36:16.111: W/System.err(1445): java.io.FileNotFoundException: /data/data/dev.shaw.MyShoppingPlanner/files/Stores/Giant_314_Horsham_Rd.txt: open failed: ENOTDIR (Not a directory)
code for this
private void generateFiles() throws IOException {
File storelist = new File(this.getFilesDir() + File.separator +"Stores");
File listnames = new File(this.getFilesDir() + File.separator + "Lists");
listnames.mkdirs();
storelist.mkdirs();
String stores[] ={"Giant Foodstore 314 Horsham Rd. Horsham Pa. 19044", "Acme Food 200 Blair Mill Rd. Horsham Pa. 19044"};
String lnames[] = {"Default List"};
String Dstorepath = storelist+File.separator + "Giant_314_Horsham_Rd.txt";
String Dlistpath = listnames + File.separator + "Default_List.txt";
File sample_store = new File(Dstorepath);
File sample_list = new File(Dlistpath);
FileOutputStream fos = new FileOutputStream(sample_store);
fos.write(stores[0].getBytes());
Toast.makeText(this,"Store File Generated" , Toast.LENGTH_SHORT).show();
fos = new FileOutputStream(sample_list);
fos.write(lnames[0].getBytes());
Toast.makeText(this,"List File Generated" , Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
source
share