How To Create Folder In Internal Memory
This is my application memory path /data/data/com.myexample.folder/files and it works fine but when I create a new directory like this /data/data/com.myexample.folder/files/photo
Solution 1:
For your own directory in file storage:
FileOutputStreamoutStream=null;
FilesdCard= Environment.getExternalStorageDirectory();
Filedir=newFile(sdCard.getAbsolutePath() + "/camtest");
dir.mkdirs();
StringfileName= String.format("%d.jpg", System.currentTimeMillis());
FileoutFile=newFile(dir, fileName);
outStream = newFileOutputStream(outFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
Intentintent=newIntent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);
For saving in sub directory inandroid public folders say DCIM:
use File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
Mainly, make sure that your app has the storage permission enabled:
Go to Device Settings>Device>Applications>Application Manager>"your app">Permissions>Enable Storage permission!
Solution 2:
Call openFileOutput() with the name of the file and the operating mode.
String FILENAME = "hello_file";
String string = "hello world!";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
Solution 3:
just use this way:
publicvoidcreateFile(Context c)throws IOException{
StringFILENAME= timeStamp();
Stringstring="hello world!";
FileOutputStreamfos= c.openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();
}
Post a Comment for "How To Create Folder In Internal Memory"