Results 1 to 1 of 1
  1. #1
    d4dirty is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Default Uploading in an ftp applet help

    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:

    Java 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:

    Java Code:
    ftpOut.write(buffer, 0, bytesRead);
    of this function:

    Java 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.
    Last edited by d4dirty; 01-07-2010 at 10:29 AM.

Similar Threads

  1. Java Applet + File Uploading
    By Moncleared in forum New To Java
    Replies: 4
    Last Post: 02-02-2009, 06:33 PM
  2. uploading a file
    By itssiva in forum Java Servlet
    Replies: 4
    Last Post: 01-16-2009, 10:41 AM
  3. File Uploading
    By aaliadhurue in forum Advanced Java
    Replies: 4
    Last Post: 01-16-2008, 06:56 PM
  4. Uploading image using JSP
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-11-2008, 09:16 AM
  5. Uploading files to FTP
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-19-2007, 10:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •