请问一下我要读取ftp上面的一个文件应该怎么实现啊

wdkb 2006-02-06 04:47:22
如题,各位帮帮忙,急用的
...全文
98 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
aspirerME 2006-02-09
  • 打赏
  • 举报
回复
import sun.net.*;
import sun.net.ftp.*;

class SFtpClient extends FtpClient
{

public boolean connect()
{
try
{
openServer(hostname,port);
login(username,password);
binary();
}
catch(FtpLoginException e)
{
return false;
}
catch (IOException e)
{
return false;
}
catch(SecurityException e)
{
return false;
}

return true;
}

public boolean getFormServer(String filename)
{
try
{
int ch;
String filepath = tempDir + filename;
File file = new File(filepath);
RandomAccessFile getFile = new RandomAccessFile(file,"rw");
getFile.seek(0);
TelnetInputStream get = get(filename);
DataInputStream put = new DataInputStream(get);

while((ch=put.read()) >= 0)
{
getFile.write(ch);
}

put.close();
get.close();
getFile.close();

return true;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}































}

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧