Search code examples
javafileinputstream

"new FileInputStream()" always get the old stream.


I'm working on a Java project. In my project I need a FileInputStream and I get it with the followed code:

FileInputStream fis = new FileInputStream("test");

but the problem is every time I get the old FileInputStream whose name is "test" but not a new one. Is there any method to avoid this behavior? Thank you!


Solution

  • Ensure that the FileInputStream is fully closed before using another FileInputStream within your method.

    fis.close();
    FileInputStream fis = new FileInputStream("test");