package com.panyang;import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;public class FileDownload { public static void main(String[] args) throws MalformedURLException, IOException {
InputStream ios=new URL("ftp://10.2.95.88/01共享目录/个人文件夹/admin/文件传递测试.rar").openConnection().getInputStream();
BufferedOutputStream bout=new BufferedOutputStream(new FileOutputStream("c:/存放目录/文件传递测试.rar"));
byte buff[]=new byte[1024];
int count;
while((count=ios.read(buff))>0){
bout.write(buff, 0, count);
}
ios.close();
bout.close();
}}请问高手们,用我上面的代码实现ftp下载文件代码有错吗??
现在运行程序时报错,如下:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
……
这个问题貌似我只能理解是地你的地址有问题了...
呵呵....
Java codepackage com.panyang;import java.io.BufferedOutputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.net.MalformedURLException;import java.net.URL;publicclass FileDownload {publicstaticvoid main(String[] args)throws MalformedURLException, IOException {
InputStream ios=new URL("ftp://10.2.95.88/01共享目录/个人文件夹/admin/文件传递测试.rar").openConnection().getInputStream();
BufferedOutputStream bout=new BufferedOutputStream(new FileOutputStream("c:/存放目录/文件传递测试.rar"));byte buff[]=newbyte[1024];int count;while((count=ios.read(buff))>0){
bout.write(buff,0, count);
}
ios.close();
bout.close();
}} 请问高手们,用我上面的代码实现ftp下载文件代码有错吗??
现在运行程序时报错,如下:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
……[/Quote]