下面是代码部分:
public static void count() throws IOException {
Properties prop = new Properties();
File file = new File("app.ini");
if (!file.exists())
file.createNewFile();
prop.load(new BufferedReader(new FileReader(file)));
int count = 0;
String appRunCount = prop.getProperty("appruncount");
if (appRunCount != null) {
count = Integer.parseInt(appRunCount);
if (count >= 5) {
System.out.println("试用次数超过限制,请注册后使用");
return;
}
}
count++;
prop.setProperty("appruncount", count + "");
prop.store(new BufferedWriter(new FileWriter(file)), "");
}
请问在我这段代码里,BufferedReader与BufferedWriter流不显示的去关闭会占用内存吗?由于匿名对象使用方便就这么写了,但是我又怕不关闭流占用内存。其实我想问的是程序会自动的帮我关闭这两个流吗?或者说匿名对象用完之后自动释放不会占用内存呢?