Reputation: 261
I want to save data in an output file using the following code. But I don't know where I find this file after the execution of the application.
try {
// open myfilename.txt for writing
OutputStreamWriter out = new OutputStreamWriter(openFileOutput("myfile.txt", Context.MODE_PRIVATE));
// write the contents on mySettings to the file
out.write("x="+Float.toString(xx)+" y="+Float.toString(yy)+" z="+Float.toString((zz))+" Puissance="+Float.toString(magneticStrenght));
// close the file
out.close();
} catch (java.io.IOException e) {
//do something if an IOException occurs.
Log.e("Exception", "File write failed: " + e.toString());
}
Thank you for your answers.
Upvotes: 1
Views: 55
Reputation: 571
This file is stored into your Application Data. You can not view this file from File manager until your Phone is rooted. So it will be better if you provide external directory path like:
File openfilename= new File(Environment.getExternalStorageDirectory(),"myfile.txt");
try {
// open myfilename.txt for writing
FileOutputStream f = new FileOutputStream(file);
// write the contents on mySettings to the file
PrintWriter pw = new PrintWriter(f);
pw.println(("x="+Float.toString(xx)
+" y="+Float.toString(yy)
+" z="+Float.toString((zz))+" Puissance="
+Float.toString(magneticStrenght));
// close the file
pw.flush();
pw.close();
f.close();
} catch (java.io.IOException e) {
//do something if an IOException occurs.
Log.e("Exception", "File write failed: " + e.toString());
}
Upvotes: 1
Reputation: 245
This file is stored into your internal storage. You will not be able to view this file externally. Give a path to external sd card for file storage if you want to view it externally
Upvotes: 1