0

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
1

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.