I am trying to write data to a FTP server using java. I am connected and everything but when I do the uploading, it only uploads some of the file. I am trying to upload like a 3 meg file but some files it will only upload like 83 bytes of it and other will upload more but not all of it unless its like a small html file or something. It's weird. Here is the relivant part of my code:
I am sure it is because byte0 is giving a -1 prematuraly but I dont even know why I am using -1 there, it was just in some other code I was looking over. How can I make sure it write the entire file to the ftp before breaking?
that did not work either as it gave an error about the 'null' that did not make sence. I changed it to -1 instead and it did the same as it did before. But I did get this to work:
while ((byte0 = bufferedinputstream.read()) != -1)
{
bufferedoutputstream.write(byte0);
}
If you read the documentation for the BufferedStreams you'll see that you should be using int, not byte. In Java, the methods are identified by there overall signatures (method name + parameters + parameter types). Just because you can pass byte as the first parameter when you provide other parameters, doesn't mean you always pass byte When passing no other argument, use int. Check the return value *before* writing to the file too (i.e. in the while condition).