private static String FileWriter() {
FileWriter fw = null;
try {
fw = new FileWriter("summer");
fw.append("_heart");
} catch (Exception e) {
return e.toString();
}
return null;
}

往常我使用FileWriter都是像上面那样写的,小项目也许还看不出问题,可如果项目一大,使用太频繁,那么,就会给系统带来巨大的压力,所以,平时写代码是应该注意几十关闭。

private static String FileWriter() {
FileWriter fw = null;
try {
fw = new FileWriter("summer");
fw.append("_heart");
} catch (Exception e) {
return e.toString();
} finally {//不管成不成功都关闭
if (fw != null) {
try {
fw.close();
} catch (Exception e2) {
return e2.toString();
}
}
}
return null;
}



相关文章:

  • 2021-10-14
  • 2021-11-23
  • 2021-08-06
  • 2022-12-23
  • 2022-01-07
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
相关资源
相似解决方案