Frage

I use

try {           
    DataOutputStream out = c.openDataOutputStream();
        String text = file + " | " + tag + " | " + report + " \n ";
        out.write(text.getBytes());
        out.close();  
    } catch (Exception e) {
        System.out.println("IOException OutputStream: "+e.getMessage());
    }`

but it removes all existing data in the file.

War es hilfreich?

Lösung

Try using:

DataOutputStream out = c.openDataOutputStream(c.fileSize());

From the API documentation for openDataOutputStream(long byteOffset)

byteOffset - number of bytes to skip over from the beginning of the file when positioning the start of the OutputStream. If the provided offset is larger than or equal to the current file size, the OutputStream is positioned at the current end of the file for appending.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top