首页 新闻 会员 周边

BufferedReader与BufferedWriter流这样用不关闭会一直驻留在内存中吗

0
悬赏园豆:5 [待解决问题]

下面是代码部分:

    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流不显示的去关闭会占用内存吗?由于匿名对象使用方便就这么写了,但是我又怕不关闭流占用内存。其实我想问的是程序会自动的帮我关闭这两个流吗?或者说匿名对象用完之后自动释放不会占用内存呢?

Jack Leonardo的主页 Jack Leonardo | 初学一级 | 园豆:107
提问于:2015-10-23 17:15
< >
分享
所有回答(1)
0

垃圾回收后会关闭吧?猜的。

Firen | 园豆:5385 (大侠五级) | 2015-10-26 06:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册