Pérdida de recursos: de entrada no se cierra nunca

Ejemplos de código

0
0

resurce pérdida de 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

Pérdida de recursos: 'entrada' no se cierra nunca

// 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();
    }            
}

En otros idiomas

Esta página está en otros idiomas

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