io - android - save file to internal storage -
i know double post other threads didn't answer question. want write file directory of app inside android directory in internal storage
i added permission manifest:
manifest.xml code:
<uses-permission android:name="android.permission.write_internal_storage" />
and java code:
file mypath = new file(getfilesdir(), "test.dat"); mypath.mkdirs(); fileoutputstream fos = null; try { fos = new fileoutputstream(mypath); fos.write(bytes); } catch (exception e) { }
however directory app not created , cannot find filename via search.
edit: there filenotfoundexception thrown, bad. thought mkdirs() create missing directories.
you can try below:
contextwrapper contextwrapper = new contextwrapper(getapplicationcontext()); file directory = contextwrapper.getdir(getfilesdir().getname(), context.mode_private); file file = new file(directory,”filename”); string data = “test data”; fileoutputstream fos = new fileoutputstream(“filename”, true); // save fos.write(data.getbytes()); fos.close();
this write file in device's internal storage (/data/user/0/com.yourapp/)
hope helps!
Comments
Post a Comment