Hi Guys,
I am fairly new to applets, and at my wits end on this one. I am writing a simple ftp file upload applet. I have been able to connect to my FTP server, but after sending 8 KB's of data of a file over I constantly get a:
|
Code:
|
java.lang.NullPointerException
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.write(Unknown Source)
at Uploader.run(Uploader.java:267)
at java.lang.Thread.run(Unknown Source) |
on this line:
|
Code:
|
ftpOut.write(buffer, 0, bytesRead); |
of this function:
|
Code:
|
BufferedOutputStream ftpOut = new BufferedOutputStream(client.storeFileStream(this.uploadedFileName));
BufferedInputStream fileIn = new BufferedInputStream(new FileInputStream(this.theFile));
// initalise some working vars
byte[] buffer = new byte[1024];
int bytesRead = fileIn.read(buffer);
long runningTotal = 0;
long total = this.theFile.length();
int percentComplete = 0;
// do the upload loop
System.out.println("Starting upload Loop");
while (bytesRead > 0)
{
System.out.println("Upload Looped writing" + percentComplete);
// write the buffer
ftpOut.write(buffer, 0, bytesRead);
// update the totals
runningTotal += bytesRead;
percentComplete = (int)((double)runningTotal / (double)total * 100);
this.txtFileName.setText("Uploaded " + getHumanReadibleFileSize(runningTotal) + " (" + percentComplete + "%)");
System.out.println("Upload Looped reading" + percentComplete);
// read some more from the input
bytesRead = fileIn.read(buffer);
} |
Is this my FTP server rejecting my upload? I just cant seem to figure out what the problem is.