Reputation: 21
I read about it but I am unable to create a folder in internal storage that i can see it.
I have tried below code
ContextWrapper contextwrapper=new ContextWrapper(MainActivity.this);
File file=new File(getfiledir(),"namefile");
Upvotes: 0
Views: 2391
Reputation: 842
Try this following, it's working fine.
File file=new File(Environment.getExternalStorageDirectory()+"/folderName");
if (!file.exists())
{
file.mkdirs();
}
String data="this is my first insert data";
File myappFile=new File(file
+ File.separator + "myapp.txt");
FileOutputStream fos = new FileOutputStream(myappFile);
fos.write(data.getBytes());
fos.close();
Must require these permissions,
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Upvotes: 2