4
Why is this line required in Java?
fout.close();
Context:
LinkedList values = new LinkedList(classe.getTurma().values());
if (!values.isEmpty()) {
FileOutputStream fout = null;
String FILE = "TURMA";
try {
fout = new FileOutputStream(FILE);
System.out.println("Tamanhno tuma" + values.size());
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(values);
} catch (FileNotFoundException ex) {
Logger.getLogger(Sistema.class
.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Sistema.class
.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fout.close();
} catch (IOException ex) {
Logger.getLogger(Sistema.class
.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
Where did you get this piece? Add an example, otherwise it is difficult to understand the problem.
– user28595
I think what he is wondering is why it is necessary to close files as a whole, not in a specific application, if that is why an open file will take up unnecessary memory space, and why it is important to close files after use. I once had a problem where I forgot to close the requisition with a bank and because of that I suffered from memory overflow.
– Erick Zanetti
put the stretch down
– Javinha
@Javinha Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero