Утечка ресурсов: ввод никогда не закрывается

Примеры кода

0
0

восстановить утечку java

public void readShapeData() throws IOException {
    Scanner in = new Scanner(System.in);
    try {
        System.out.println("Enter the width of the Rectangle: ");
        width = in.nextDouble();
        System.out.println("Enter the height of the Rectangle: ");
        height = in.nextDouble();
    } finally {
        in.close();
    }
}
0
0

Утечка ресурсов: "ввод" никогда не закрывается

// You need to close Scanner. It can run, but there will be resource problems in the future.

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    String txt = input.nextLine();
    System.out.println("input "+txt);           
}

// Change to
public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    try{
        String txt = input.nextLine();
        System.out.println("input "+txt);
    } finally {
        input.close();
    }            
}

На других языках

Эта страница на других языках

English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................