资源泄漏:'in'从不关闭 [英] Resource leak: 'in' is never closed

查看:175
本文介绍了资源泄漏:'in'从不关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 为什么Eclipse会让我变暖资源泄漏:在以下代码中永远不会关闭? public void readShapeData(){
扫描仪in = new Scanner(System.in);
System.out.println(输入Rectangle的宽度);
width = in.nextDouble();
System.out.println(输入Rectangle的高度);
height = in.nextDouble();


解决方案

因为您没有关闭扫描仪

  in.close(); 


Why does Eclipse give me the warming "Resource leak: 'in' is never closed" in the following code?

public void readShapeData() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the width of the Rectangle: ");
        width = in.nextDouble();
        System.out.println("Enter the height of the Rectangle: ");
        height = in.nextDouble();

解决方案

Because you don't close your Scanner

in.close();

这篇关于资源泄漏:'in'从不关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆