Reputation: 14711
This is how I save files to InternalStorage
public static boolean saveInputStreamToInternalStorageFile(Context context, String filename, byte[] dataToWrite, Context ctx) {
FileOutputStream fos;
try {
fos = new FileOutputStream(context.getFilesDir() + File.separator + filename);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(dataToWrite);
oos.close();
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
How do I change that code, so that files are now saved into a subdirectory of that folder, called "media/"?
Upvotes: 1
Views: 55
Reputation: 1006604
Replace:
fos = new FileOutputStream(context.getFilesDir() + File.separator + filename);
with:
File media=new File(context.getFilesDir(), "media");
media.mkdirs();
fos = new FileOutputStream(new File(media, filename));
Upvotes: 4