java.io.IOException: Stream closed

I try to copy mre files

for(int i = 0; i < 3; i++){

File outputFile =new File(path);

InputStream ins = this.getClass().getResourceAsStream("/"+_files[i]);

BufferedInputStream input =new BufferedInputStream(ins);

FileOutputStream outfile =new FileOutputStream(outputFile);

int read;

byte[] buffer =newbyte[4096];

while ((read=input.read(buffer))!=-1){

outfile.write(buffer, 0, read);

}

outfile.close();

input.close();

}

Exception

java.io.IOException: Stream closed

at java.io.BufferedInputStream.getInIfOpen(Unknown Source)

at java.io.BufferedInputStream.fill(Unknown Source)

at java.io.BufferedInputStream.read1(Unknown Source)

at java.io.BufferedInputStream.read(Unknown Source)

at java.io.FilterInputStream.read(Unknown Source)

what shoud be the problem

[1365 byte] By [the_Orienta] at [2007-11-27 0:16:15]
# 1
What makes you sure it is coming from this code?I would suggest running this code from a command line app rather than wrapped in whatever it is wrapped in which doesn't let you see the source lines.
jschella at 2007-7-11 22:03:55 > top of Java-index,Java Essentials,Java Programming...
# 2

public vpid copyImages(...)

{

for(int i = 0; i < 3; i++){

File outputFile = new File(path);

InputStream ins = this.getClass().getResourceAsStream("/"+_files[i]);

BufferedInputStream input = new BufferedInputStream(ins);

FileOutputStream outfile = new FileOutputStream(outputFile);

int read;

byte[] buffer = new byte[4096];

while ((read=input.read(buffer))!=-1){

outfile.write(buffer, 0, read);// line 1575

}

outfile.close();

input.close();

}

Exception

java.io.IOException: Stream closed

at java.io.BufferedInputStream.getInIfOpen(Unknown Source)

at java.io.BufferedInputStream.fill(Unknown Source)

at java.io.BufferedInputStream.read1(Unknown Source)

at java.io.BufferedInputStream.read(Unknown Source)

at java.io.FilterInputStream.read(Unknown Source)

at app.org.SQLFactory.copyImagesToIMGServer(SQLFactory.java:1575)

what shoud be the problem and how to resulve this problem

thanks

the_Orienta at 2007-7-11 22:03:55 > top of Java-index,Java Essentials,Java Programming...
# 3

It is trivially apparent from the stack trace that the problem is that at at app.org.SQLFactory.copyImagesToIMGServer(SQLFactory.java:1575) you are trying to read from a BufferedInputStream that you've already closed or which wasn't open in the first place.

How that corresponds to the source code you've provided is anybody's guess.

ejpa at 2007-7-11 22:03:55 > top of Java-index,Java Essentials,Java Programming...
# 4

I did not close the steeam

this is the code

public vpid copyImages()

{

String [] _files ={"b1.jpg",b2.jpg,b3.jpg};

for(int i = 0; i < _files.length; i++){

File outputFile = new File(path);

InputStream ins = this.getClass().getResourceAsStream("/"+_files[i]);

BufferedInputStream input = new BufferedInputStream(ins);

FileOutputStream outfile = new FileOutputStream(outputFile);

int read;

byte[] buffer = new byte[4096];

while ((read=input.read(buffer))!=-1){

outfile.write(buffer, 0, read);// line 1575

}// end while

outfile.close();

input.close();

} // end for

Exception

java.io.IOException: Stream closed

at java.io.BufferedInputStream.getInIfOpen(Unknown Source)

at java.io.BufferedInputStream.fill(Unknown Source)

at java.io.BufferedInputStream.read1(Unknown Source)

at java.io.BufferedInputStream.read(Unknown Source)

at java.io.FilterInputStream.read(Unknown Source)

at app.org.SQLFactory.copyImagesToIMGServer(SQLFactory.java:1575)

the_Orienta at 2007-7-11 22:03:55 > top of Java-index,Java Essentials,Java Programming...
# 5
In fact you never even checked whether it was open in the first place. getResourceAsStream can return null ...Not to mention that not even the third version of your code compiles.
ejpa at 2007-7-11 22:03:55 > top of Java-index,Java Essentials,Java Programming...
# 6
you really should check if the inputStream that you are getting is != null, this can often be the case for the error that you getting
Octaclota at 2007-7-11 22:03:55 > top of Java-index,Java Essentials,Java Programming...