The tool class that was written a few days ago, and the Ftp.storefilestream that appeared at the time of the new test did not get the stream object. The wait time problem occurs.
Tracking code, login No problem! Go to FTP to see some directory structure and files. The discovery file has been created, but there is no content inside. An estimate is the reason that the stream object cannot write to the content.
For this question to see some of the information on the Internet, and then compare some of their own code. Found themselves after landing did not do exit and disconnect processing, plus these after the problem solved.
Here's the code:
1 Public Static Booleanputfiletoftp (File file,string newfilepathname) {2 BooleanFlag =false;3 //Create an FTP client4FtpClient FTP =getclient ();5 Try {6 //Login7 Ftp.connect (Rehostname, Integer.parseint (report));8Flag =Ftp.login (Reusername, Repassword);9 if(flag) {Ten //Set upload directory One Ftp.enterlocalpassivemode (); AFtp.setcharset (Charset.forname ("UTF-8")); -Ftp.setcontrolencoding ("UTF-8"); - //set File type (binary) the Ftp.setfiletype (ftpclient.binary_file_type); - //file Stream Output -OutputStream OS = Ftp.storefilestream (retrumpetheserver+ "/" +newfilepathname); - if(os!=NULL){ +FileInputStream FIS =Newfileinputstream (file); - byte[] B =New byte[1024]; + intLen = 0; A while(len = Fis.read (b))! =-1) { atOs.write (b,0, Len); - } - fis.close (); - os.close (); - ftp.logout (); -Flag =true; in}Else{ - ftp.logout (); to return false; + } -}Else{ the Ftp.disconnect (); * return false; $ }Panax Notoginseng - the}Catch(IOException e) { + e.printstacktrace (); A return false; the}finally { + Try { - Ftp.disconnect (); $}Catch(IOException e) { $ e.printstacktrace (); - Throw NewRuntimeException ("Close FTP connection exception occurred! ", E); - } the } - returnFlag; Wuyi}
The above is the code and may not be considered comprehensive enough. Please use it carefully!
About FTP file upload get Stream object null value problem