Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

BufferedInputStream to file? File gets corrupted!

807606May 14 2007 — edited May 14 2007
I am downloading files from an ftp and I use the following code to write the inputstream (from the ftp) to a file, but the written file differs from the original. Why? What am I doing wrong? The original file is 2,572,288 bytes but the downloaded file is 2,584,941 bytes
System.out.println("Starting download!!!");
boolean downloading = true;
int loaded = 0;
BufferedInputStream inStream = new BufferedInputStream(ftp.retrieveFileStream("godansen.avi"));
fileWriter = new FileOutputStream("c:\\temp\\" + "godansen.avi");

	while(downloading){
		byte pakke[] = new byte[5];
		int byteval = inStream.read(pakke, 0, 5);
		if (byteval!=-1){
			fileWriter.write(pakke, 0, byteval);
			fileWriter.flush();
		}else{
			downloading = false;
		}
		loaded += 5;
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 11 2007
Added on May 14 2007
25 comments
1,369 views