Does Java’s Try-catch-Resources flush automatically?

Asked

Viewed 60 times

3

When using an object of the type FileInputStream and FileOutputStream within a Try-catch-Resources java automatically uses the close-up() in the end, but, and the flush() is automatic or not?

// Exemplo
try(FileOutputStream fos = new FileOutputStream("arquivo.txt")){
    try (BufferedOutputStream bos = new BufferedOutputStream(fos)) {
        bos.write("Teste");
        bos.flush(); // Precisa usar o flush()
    }
    fos.flush(); // Precisa usar o flush()
}

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.