Java:写文件时除了流以外,File也需要关闭?
protectedvoidwriteFile(Stringfilename,ArrayListclientReqs,inti){try{OutputStreamouts=...
protected void writeFile(String filename, ArrayList clientReqs, int i) {
try {
OutputStream outs = new FileOutputStream(new File(filename));
ObjectOutputStream oos = new ObjectOutputStream(outs);
oos.writeObject(clientReqs.get(i));
oos.flush();
oos.close();
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
}
我这里将流都关闭了,但是new出来的File也需要关闭?怎么关闭...... 展开
try {
OutputStream outs = new FileOutputStream(new File(filename));
ObjectOutputStream oos = new ObjectOutputStream(outs);
oos.writeObject(clientReqs.get(i));
oos.flush();
oos.close();
} catch (FileNotFoundException ex) {
} catch (IOException ex) {
}
}
我这里将流都关闭了,但是new出来的File也需要关闭?怎么关闭...... 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询