java - Ftp file downloaded path has problem? -
i have java code file download through ftp, after download file, goes default path. specified destination path not having downloaded file. why? code is,
public class ftpupload1 { public static void main(string a[]) throws ioexception { ftpupload1 obj = new ftpupload1(); url url1 = new url("ftp://vbalamurugan:vbalamurugan@192.168.6.38/ddd.txt" ); file dest = new file("d:/rvenkatesan/software/ddd.txt"); obj.ftpdownload(dest, url1); public void ftpdownload(file destination,url url) throws ioexception { bufferedinputstream bis = null; bufferedoutputstream bos = null; try { urlconnection urlc = url.openconnection(); bis = new bufferedinputstream( urlc.getinputstream() ); bos = new bufferedoutputstream( new fileoutputstream(destination.getname() ) ); int i; //read byte byte until end of stream while ((i = bis.read())!= -1) { // bos.write(i); bos.write(i); } system.out.println("file downloaded successfully"); } { if (bis != null) try { bis.close(); } catch (ioexception ioe) { ioe.printstacktrace(); } if (bos != null) try { bos.close(); } catch (ioexception ioe) { ioe.printstacktrace(); } } } } }
the downloaded file "ddd.txt" not in "d:/rvenktesan/software". located in "d:rvenkatesan/java projects". why? guide me store file in specified path? in adcance.
you problem fileoutputstream(destination.getname() ) );
change to: fileoutputstream(destination.getabsolutepath() ) );
getname wil return filename "ddd.txt" only. assume starting app d:/rvenkatesan/java projects
Comments
Post a Comment