dcsimg
how can i copy an image file.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sanjeev_Mehra
Posted On:   Thursday, April 10, 2003 07:20 AM


copying a (text) file is not a problem using java.io pack but when i try to apply same with an image file, destination file gives unwanted result.

Re: how can i copy an image file.

Posted By:   Jonathan_Downey  
Posted On:   Friday, April 11, 2003 07:13 AM

It works the same way. I'd say that the Text file is also corrupt, in that an extra byte of data has been added or omitted but that you haven't noticed it in the text file.

Typically:

public void copyFile(String from, String to) throws Exception{
FileInputStream istr = null;
FileOutputStream ostr = null;
byte buffer[] = new byte[1024];

try {
istr = new FileInputStream( from );
ostr = new FileOutputStream( to );

int num = 0;

do {
num = istr.read( buffer );

if(num > 0)
ostr.write(buffer, 0, num );
} while(num !=-1 );

}
finally {
if(istr!=null)
istr.close();
if(ostr!=null)
ostr.close();
}
}

That works for me.

Jonathan

Re: how can i copy an image file.

Posted By:   Steven_Martin  
Posted On:   Thursday, April 10, 2003 07:27 AM

What's your code?
About | Sitemap | Contact