How to create files to a specific folder in android application? -


in application, want create text file in cache folder , first create folder in cache directory.

file mydir = new file(getcachedir(), "mysecretfolder"); mydir.mkdir(); 

then want create text file in created folder using following code doesn't seem make there. instead, code below creates text file in "files" folder in same directory "cache" folder.

fileoutputstream fout = null;             try {                 fout = openfileoutput("secret.txt",mode_private);             } catch (filenotfoundexception e) {                 e.printstacktrace();             }             string str = "data";             try {                 fout.write(str.getbytes());             } catch (ioexception e) {                 e.printstacktrace();             }             try {                 fout.close();             } catch (ioexception e) {                 e.printstacktrace();             } 

so question is, how designate "mysecretfolder" make text file in?

i have tried following:

"/data/data/com.example.myandroid.cuecards/cache/mysecretfolder", crashes entire app if try that. how should save text file in cache/mysecretfolder?

just change

fout = openfileoutput("secret.txt",mode_private); 

to

fout = openfileoutput(mydir+"/secret.txt",mode_private); 

this make secret.txt under mysecretfolder


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -