Tag Archives: Resource leak: ‘xxx’ is never closed(Scanner

Error log: resource leak: ‘xxx’ is never closed (precautions for scanner class)

This article gives you a comprehensive understanding of Java object serialization and deserialization>>>

When using the scanner class, for example:

 1 import java.util.Scanner;
 2 public class data {
 3 
 4      public static void main(String[] args){
 5          Scanner i=new Scanner(System.in);
 6          float j=i.nextFloat();
 7          System.out.println(j); 8      }
 9 }

A warning appears

Resource leak: 'i' is never closed

error reason: the data input scanner named I is declared, so as to obtain the configuration memory,

but the memory is not closed or released at the end, and a warning appears. Therefore, I. close () is used at the end of the mian function; End the data stream and free the memory