Skip to content
Advertisement

The Properties.load would close the InputStream?

I saw this example, and I didn’t see the close() method invoked on the InputStream, so would prop.load() close the stream automatically? Or is there a bug in the example?

Advertisement

Answer

The Stream is not closed after Properties.load ()

public static void main(String[] args) throws IOException {

    InputStream in = new FileInputStream(new File("abc.properties"));

    new Properties().load(in);

    System.out.println(in.read());
}

The above code returns “-1” so the stream is not closed. Otherwise it should have thrown java.io.IOException: Stream Closed

Advertisement