首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

sun.net.TelnetProtocolException: misplaced CR in input的错误

2012-10-07 
sun.net.TelnetProtocolException: misplaced CR in input的异常比如要下载ftp://ftp.xx.com/index.html则

sun.net.TelnetProtocolException: misplaced CR in input的异常

比如要下载ftp://ftp.xx.com/index.html则:

import sun.net.ftp.FtpClient;
import java.io.*;
import sun.net.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @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");

fc.binary();//这一句很关键,因为我是下载rar文件.如果不加会出现sun.net.TelnetProtocolException: misplaced CR in input的异常.
??????????? 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();
??????? }

??? }
}


如果文件在某个目录下,则加入fc.cd("foodir");

?

热点排行