0

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.txt 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 ?

4

1 に答える 1

0

ファイルを複数回書き込み可能にするにはContext.MODE_APPEND

サンプルコード

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();
            }

ありがとうディーパック

于 2011-06-15T14:38:58.953 に答える