Android application cant write to file at second time
I have problem with writing data to file in Android Emulator. In my Android Emulator in /data folder I have created MyLogs folder and give full access to it. After I run my application and it create Log.t开发者_运维知识库xt file and place it in /data/MyLogs folder. All is Okay. After I have run my application in second time and application try to write some information in same file, but it cant't.
I think the main reason is that then at first time my application creates file the creator is different from second time. thats why I can't write to file second time !
Who have any ideas ?
To make a file writable for more than once use Context.MODE_APPEND
Sample Code
FileOutputStream fos;
try {
fos = openFileOutput("nuzz.txt", Context.MODE_APPEND);
fos.write(string.getBytes());
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fos = openFileOutput("nuzz.txt", Context.MODE_APPEND);
fos.write("bye".getBytes());
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thanks Deepak
精彩评论