I am using BufferedInputStream and BufferedOutputStream to transfer files in batches of 1024 bytes since the file size varies from 1024Byes to 500MB. BufferedOutputStream is unable to write if buffer size is less than 1024 bytes. It transfers files with zero bytes. It is working fine for file size > 1024 bytes Any help will be appreciated.
I'm not sure where your problem could be. I've used the same thing Sun's FtpClient, BufferOutputStream and successfully sent files as small as 64 bytes. Post a code example and we'll see if we can help.
Originally posted by Carl Trusiak: I'm not sure where your problem could be. I've used the same thing Sun's FtpClient, BufferOutputStream and successfully sent files as small as 64 bytes. Post a code example and we'll see if we can help.
Here is the code, please let me know whats wrong with this code.
I added the UBB tags Code for easier reading. How to use UBB tags can be found Here [This message has been edited by Carl Trusiak (edited February 22, 2001).]
Joined: Jun 13, 2000
Wow, try simplifing this to:
That's about all I used and it worked fine.
[This message has been edited by Carl Trusiak (edited February 22, 2001).]
Joined: Feb 20, 2001
When I started, my code was like that way only. After that I observed that last 1024 bytes were not transfered properly. Thats the reason I changed my code like the way it is now.
Joined: Jun 13, 2000
Like I said, I used the exact code I posted and had no problems. I have to caution on using Sun's FtpClient, it's an unsupported package and it could just be the version you are using. Try refactoring you code and include the Socket based FTPClient Jeff Holmes contributed. It's not fully complete but, should have enough for your task http://www.javaranch.com/ubb/Forum38/HTML/000066.html
Try adding the bout.flush to the portion of the code when there's less than 1024 bytes. See code below. I was having the same problem until I used the bout.flush(); to flush the buffer.
System.out.println("No of Bytes in file" + bReader.available()); byte buffer = new byte[bReader.available()]; int lastReadCount = bReader.read(buffer); bout.write(buffer,0,lastReadCount); total = total + lastReadCount; bout.flush(); System.out.println(total);