I have an android app and simply i need to store data in a file. I need to use external storage to make it available for other applications too. im using this piece of code
BufferedWriter bw;
try {
bw = new BufferedWriter(new FileWriter("/storage/sdcard0/download/themagicfile.txt", true));
bw.write("hi");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
which i got from http://stackoverflow.com/questions/10041007/write-to-txt-file-but-not-overwrite
I can see the file in the directory but when i open it there is nothing in it. i need to use FileWriter to make it appendable.
any suggestion
asked Apr 15, 2014 at 15:08
Vivere_FlowCoder
2771 gold badge4 silver badges14 bronze badges
-
Also check - stackoverflow.com/questions/11386441/…sjain– sjain2014年04月15日 15:14:36 +00:00Commented Apr 15, 2014 at 15:14
1 Answer 1
you should also call
bw.flush();
bw.close();
rembember to add the WRITE_EXTERNAL_STORAGE permission to the AndroidManifest.xml file
try {
bw = new BufferedWriter(new FileWriter("/storage/sdcard0/download/themagicfile.txt", true));
bw.write("hi");
bw.flush();
} (IOException e) {
e.printStackTrace();
} finally {
try {
bw.close();
} (IOException e) { }
}
answered Apr 15, 2014 at 15:09
Blackbelt
158k31 gold badges308 silver badges310 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Vivere_FlowCoder
I could see the text after this. But i needed to refresh the file manager in my device. it just doesnt show it write away. even if the usb Cable is not connected to laptop..why? is there any solutoin for that that i can use inside a code?
default