比如要下载ftp://ftp.xx.com/index.html则: import sun.net.ftp.FtpClient; import java.io.*; import sun.net.*; /** *
Title:
*Description:
*Copyright: Copyright (c) 2004
*Company:
* @author petehero * @version 1.0 */ public class ftpDown { public ftpDown() { } public static void main(String[] args) { try { FtpClient fc=new FtpClient("ftp.xx.com"); fc.login("username","888888"); int ch; File fi = new File("c://index.html"); RandomAccessFile getFile = new RandomAccessFile(fi,"rw"); getFile.seek(0); TelnetInputStream fget=fc.get("index.html"); DataInputStream puts = new DataInputStream(fget); while ((ch = puts.read()) >= 0) { getFile.write(ch); } fget.close(); getFile.close(); fc.closeServer(); } catch (IOException ex) { ex.printStackTrace(); } } }