Reputation: 183
My Code is:
String MyFile = "Riseone.dat";
String MyContent = "This is My file im writing\r\n";
File file;
FileOutputStream outputStream;
try {
file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS),MyFile);
outputStream = new FileOutputStream(file);
outputStream.write(MyContent.getBytes());
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
When I try this code MyFile creates in data/data/appfolder/files/Riseone.dat but I want to create a file in DIRECTORY_DOWNLOADS.
also I want the file to write in append for next write action.
Upvotes: 3
Views: 1553
Reputation: 16389
new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), MyFile);
corresponds to the file inside the Downloads
directory of external shared storage. You might have seen older file in internal storage. Check it carefully.
If you want to append the data for next write, use append mode to create FileOutputStream
using another constructor public FileOutputStream(File file, boolean append)
outputStream = new FileOutputStream(file, true);
Upvotes: 2