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()
}
Yes, the flush is also automatic. See this example: Java Try/catch/Finally best Practices
– Leonardo Pessoa