Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top