this is a code snippet from a project I'm working on now:
from inside an action / context:
File dir = getDir("Foler", 0); // i think your problem is here File file = new File(dir,"File.bin");
creating a directory in android is different from java on a regular computer, try creating your directory using getDir () instead of a new file (...). mkdirs () and make sure it is inside the context (after activity is created)
I do not believe that I am the best to answer this question, since I am also new to android, but maybe this helps
so the final code could be like that
File dir = getDir("subdir",0); File imageFile = new File(dir, "filename.txt"); imageFile.createNewFile(); FileOutputStream outputStream = new FileOutputStream(imageFile);
I don't know about creating subdirectories, I still haven't tried it
source share