使用JAVA语言 如何将文件从服务器下载入指定的本地文件夹内?(FTP) 急用 在线等 我已经能够实现文件的下载 但是文件总是自动下载到工程目录下 如何下载到指定目录呢?比如我希望他能够下载到"D:/" 知道的请指点下~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 FtpClient ftp = new FtpClient(host); ftp.login(username, password); ftp.binary(); ftp.cd(path); while((s=dr.readLine())!=null) { System.out.println(a(s)); getfile = ftp.get(a(s)); str = ftp.getResponseString (); System.out.println(str); FileOutputStream output = new FileOutputStream (new File (a(s))); while( true ) { int y = getfile.read(); if( y == -1 ) break; else { output.write ((byte)y); output.flush(); } } getfile.close(); output.close (); }public static String a(String s) { String s1=""; StringTokenizer st=new StringTokenizer(s," "); s1=st.nextToken(); while(st.hasMoreTokens()) { s=st.nextToken(); } if (s1.indexOf("-")!=-1) s2=s ; else s2 = null; return s1.indexOf("-")==-1?"Folder:"+s:"File:"+s; } String server=Server; String user=User; String password=Pass; String path=FtpPath; try { FtpClient ftpClient = new FtpClient(); //创建FtpClient对象 ftpClient.openServer(server,this.Port); //连接FTP服务器 ftpClient.login(user, password); //登录FTP服务器 if (path.length() != 0) ftpClient.cd(path); //下载一个文件 ftpClient.binary(); TelnetInputStream is = ftpClient.get(FileName); File file_out = new File(SavePath+FileName); FileOutputStream os = new FileOutputStream(file_out); byte[] bytes = new byte[1024]; int c; while ( (c = is.read(bytes)) != -1) { os.write(bytes, 0, c); } is.close(); os.close(); ftpClient.closeServer(); //退出FTP服务器 } catch (Exception ex) { } 谢谢楼上的 我已经实现下载了 我是希望能把文件下载到本地计算机指定的目录中去 比如下到“D:/” 楼上的和我自己的代码都只能够实现把文件下载到我所建立的这个JAVA项目中的文件夹里 我不想让他那么死 想灵活一些 让他下载入我指定的文件 如何实现呢? 晕,楼主仔细看看SavePath+FileName,就是你指定的目录呀 运行下来还是下载到了项目目录 没有下到目标文件夹~ getfile = ftp.get(filename3); str = ftp.getResponseString (); System.out.println(str); File file_out = new File("D:/"+filename3); FileOutputStream os = new FileOutputStream(file_out); // FileOutputStream output = new FileOutputStream (new File (filename3)); while( true ) { int y = getfile.read(); if( y == -1 ) break; else { os.write ((byte)y); os.flush(); //output.flush(); } } getfile.close(); os.close ();楼上帮我看下 我哪里写错了么? socket为何会自己closed? 求助:如何通过java代码获得通过局域网上网的某台机子的局域网ip地址? 对access数据库实行insert时的问题 java连SQL Server数据库 如何实现图片在网络间的传递? 这两条理论之间是否存在一些矛盾呢? java正则表达式匹配 JDK1.3下的程序能完全在JDK1.4下运行吗? 关于jdbc异常:java.sql.SQLException: No data found 郁闷 关于用户体验中枚举和正则表达式的问题.. 已经可以实现下载了 如何实现将文件下载到“指定”的目录中去??(FTP) 急~ 在线等 JNATIVE求助!
ftp.login(username, password);
ftp.binary();
ftp.cd(path);
while((s=dr.readLine())!=null) {
System.out.println(a(s)); getfile = ftp.get(a(s));
str = ftp.getResponseString ();
System.out.println(str);
FileOutputStream output = new FileOutputStream (new File (a(s)));
while( true )
{
int y = getfile.read();
if( y == -1 ) break;
else
{
output.write ((byte)y);
output.flush();
}
}
getfile.close();
output.close ();
}public static String a(String s) {
String s1="";
StringTokenizer st=new StringTokenizer(s," ");
s1=st.nextToken();
while(st.hasMoreTokens())
{ s=st.nextToken();
}
if (s1.indexOf("-")!=-1)
s2=s ;
else
s2 = null;
return s1.indexOf("-")==-1?"Folder:"+s:"File:"+s; }
String server=Server;
String user=User;
String password=Pass;
String path=FtpPath; try {
FtpClient ftpClient = new FtpClient();
//创建FtpClient对象
ftpClient.openServer(server,this.Port);
//连接FTP服务器
ftpClient.login(user, password);
//登录FTP服务器
if (path.length() != 0) ftpClient.cd(path); //下载一个文件
ftpClient.binary(); TelnetInputStream is = ftpClient.get(FileName); File file_out = new File(SavePath+FileName);
FileOutputStream os = new FileOutputStream(file_out);
byte[] bytes = new byte[1024];
int c;
while ( (c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}
is.close();
os.close(); ftpClient.closeServer(); //退出FTP服务器
} catch (Exception ex) {
}
我是希望能把文件下载到本地计算机指定的目录中去 比如下到“D:/”
楼上的和我自己的代码都只能够实现把文件下载到我所建立的这个JAVA项目中的文件夹里 我不想让他那么死 想灵活一些 让他下载入我指定的文件 如何实现呢?
getfile = ftp.get(filename3);
str = ftp.getResponseString ();
System.out.println(str);
File file_out = new File("D:/"+filename3);
FileOutputStream os = new FileOutputStream(file_out);
// FileOutputStream output = new FileOutputStream (new File (filename3));
while( true )
{
int y = getfile.read();
if( y == -1 ) break;
else
{
os.write ((byte)y);
os.flush();
//output.flush();
}
}
getfile.close();
os.close ();
楼上帮我看下 我哪里写错了么?