w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
FileInputStream is getting closed when passing second time to a function in java

Because your fileCopy() method explicitly closes it.

You pass fileInputStream to fileCopy():

fileCopy(fileInputStream, fileOutputStream1);

And inside fileCopy():

fileInputStream.close();

When fileCopy() returns, the fileInputStream and fileOutputStream parameters are closed. But even if fileInputStream would not be closed, it would not point to the beginning of the file anymore (because fileCopy() uses it to read bytes from the file). Easiest in your case is to just create a new FileInputStream when you want to call fileCopy() again.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.