java - Unable to write to Text File Exist in FTP server -
i use below code write text file exists in ftp server.but got java.net.malformedurlexception
url url = new url("ftp://p@g.com:g@1234@ftp.xyz.com/testjar/2014-03-06-p.txt;type=i"); urlconnection urlc = url.openconnection(); outputstream os = urlc.getoutputstream(); // upload outputstream buffer = new bufferedoutputstream(os); objectoutput output = new objectoutputstream(buffer); output.writeobject("hiiiii"); buffer.close(); os.close(); output.close();
above username , password not real demo looks real. know how solve issue or other method write .txt file,let me inform.
edit1:also username , pass contains @ char , in pass number there. full error:
java.net.malformedurlexception: input string: "g@1234@ftp.xyz.com" @ java.net.url.<init>(url.java:619) @ java.net.url.<init>(url.java:482) @ java.net.url.<init>(url.java:431) @ createfolder.uploadfile(createfolder.java:39) @ createfolder.main(createfolder.java:74) caused by: java.lang.numberformatexception: input string: "g@1234@ftp.xyz.com" @ java.lang.numberformatexception.forinputstring(numberformatexception.java:65) @ java.lang.integer.parseint(integer.java:492) @ java.lang.integer.parseint(integer.java:527) @ java.net.urlstreamhandler.parseurl(urlstreamhandler.java:217) @ java.net.url.<init>(url.java:614) ... 4 more
you didn't provide error see couple of issues here:
- connection string: know it's example if real user/pass contain '@' char, url won't parsed.
objectoutputstream
class intended write object data can reconstructedobjectinputstream
(see here). it's not writing textual files. if need writing string stream better use printstream
so revised example be:
try { url url = new url("ftp://user:pass@ftp.xyz.com/testjar/2014-03-06-p.txt;type=i"); urlconnection urlc = url.openconnection(); outputstream os = urlc.getoutputstream(); // upload outputstream buffer = new bufferedoutputstream(os); printstream output = new printstream(buffer); output.print("hiiiii"); } catch (ioexception ex) { ex.printstacktrace(); } { output.close(); buffer.close(); os.close(); }
Comments
Post a Comment