java写文件到ftp|如何用Java实现FTP服务器

❶ 用java有一个ftp路径地址,需要把传送一些数据到ftp中怎样实现

1.使用的FileZillaServer开源,安装过后建立的本地FTP服务器。2.使用的apache上FTP工具包,引用到工程目录中。3.IDE,Eclipse,JDK6上传和目录的实现原理:对每一个层级的目录进行判断,是为目录类型、还是文件类型。如果为目录类型,采用递归调用方法,检查到最底层的目录为止结束。如果为文件类型,则调用上传或者方法对文件进行上传或者操作。贴出代码:(其中有些没有代码,可以看看,还是很有用处的)!

❷ java获取ftp文件路径怎么写

com.weixin.util;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.PrintWriter;import java.io.RandomAccessFile;import org.apache.commons.net.PrintCommandListener;import org.apache.commons.net.ftp.FTP;import org.apache.commons.net.ftp.FTPClient;import org.apache.commons.net.ftp.FTPFile;import org.apache.commons.net.ftp.FTPReply;import com.weixin.constant.DownloadStatus;import com.weixin.constant.UploadStatus;/*** 支持断点续传的FTP实用类* @version 0.1 实现基本断点上传下载* @version 0.2 实现上传下载进度汇报* @version 0.3 实现中文目录创建及中文文件创建,添加对于中文的支持*/public class ContinueFTP {public FTPClient ftpClient = new FTPClient();public ContinueFTP(){//设置将过程中使用到的命令输出到控制台this.ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));}/*** 连接到FTP服务器* @param hostname 主机名* @param port 端口* @param username 用户名* @param password 密码* @return 是否连接成功* @throws IOException*/public boolean connect(String hostname,int port,String username,String password) throws IOException{ftpClient.connect(hostname, port);ftpClient.setControlEncoding("GBK");if(FTPReply.isPositiveCompletion(ftpClient.getReplyCode())){if(ftpClient.login(username, password)){return true;}}disconnect();return false;}/*** 从FTP服务器上下载文件,支持断点续传,上传百分比汇报* @param remote 远程文件路径* @param local 本地文件路径* @return 上传的状态* @throws IOException*/public DownloadStatus download(String remote,String local) throws IOException{//设置被动模式ftpClient.enterLocalPassiveMode();//设置以二进制方式传输ftpClient.setFileType(FTP.BINARY_FILE_TYPE);DownloadStatus result;//检查远程文件是否存在FTPFile[] files = ftpClient.listFiles(new String(remote.getBytes("GBK"),"iso-8859-1"));if(files.length != 1){System.out.println("远程文件不存在");return DownloadStatus.Remote_File_Noexist;}long lRemoteSize = files[0].getSize();File f = new File(local);//本地存在文件,进行断点下载if(f.exists()){long localSize = f.length();//判断本地文件大小是否大于远程文件大小if(localSize >= lRemoteSize){System.out.println("本地文件大于远程文件,下载中止");return DownloadStatus.Local_Bigger_Remote;}//进行断点续传,并记录状态FileOutputStream out = new FileOutputStream(f,true);ftpClient.setRestartOffset(localSize);InputStream in = ftpClient.retrieveFileStream(new String(remote.getBytes("GBK"),"iso-8859-1"));byte[] bytes = new byte[1024];long step = lRemoteSize /100;long process=localSize /step;int c;while((c = in.read(bytes))!= -1){out.write(bytes,0,c);localSize+=c;long nowProcess = localSize /step;if(nowProcess > process){process = nowProcess;if(process % 10 == 0)System.out.println("下载进度:"+process);//TODO 更新文件下载进度,值存放在process变量中}}in.close();out.close();boolean isDo = ftpClient.completePendingCommand();if(isDo){result = DownloadStatus.Download_From_Break_Success;}else {result = DownloadStatus.Download_From_Break_Failed;}}else {OutputStream out = new FileOutputStream(f);InputStream in= ftpClient.retrieveFileStream(new String(remote.getBytes("GBK"),"iso-8859-1"));byte[] bytes = new byte[1024];long step = lRemoteSize /100;long process=0;long localSize = 0L;int c;while((c = in.read(bytes))!= -1){out.write(bytes, 0, c);localSize+=c;long nowProcess = localSize /step;if(nowProcess > process){process = nowProcess;if(process % 10 == 0)System.out.println("下载进度:"+process);//TODO 更新文件下载进度,值存放在process变量中}}in.close();out.close();boolean upNewStatus = ftpClient.completePendingCommand();if(upNewStatus){result = DownloadStatus.Download_New_Success;}else {result = DownloadStatus.Download_New_Failed;}}return result;}/*** 上传文件到FTP服务器,支持断点续传* @param local 本地文件名称,绝对路径* @param remote 远程文件路径,使用/home/directory1/subdirectory/file.ext 按照Linux上的路径指定方式,支持多级目录嵌套,支持递归创建不存在的目录结构* @return 上传结果* @throws IOException*/public UploadStatus upload(String local,String remote) throws IOException{//设置PassiveMode传输ftpClient.enterLocalPassiveMode();//设置以二进制流的方式传输ftpClient.setFileType(FTP.BINARY_FILE_TYPE);ftpClient.setControlEncoding("GBK");UploadStatus result;//对远程目录的处理String remoteFileName = remote;if(remote.contains("/")){remoteFileName = remote.substring(remote.lastIndexOf("/")+1);//创建服务器远程目录结构,创建失败直接返回if(CreateDirecroty(remote, ftpClient)==UploadStatus.Create_Directory_Fail){return UploadStatus.Create_Directory_Fail;}}//检查远程是否存在文件FTPFile[] files = ftpClient.listFiles(new String(remoteFileName.getBytes("GBK"),"iso-8859-1"));if(files.length == 1){long remoteSize = files[0].getSize();File f = new File(local);long localSize = f.length();if(remoteSize==localSize){return UploadStatus.File_Exits;}else if(remoteSize > localSize){return UploadStatus.Remote_Bigger_Local;}//尝试移动文件内读取指针,实现断点续传result = uploadFile(remoteFileName, f, ftpClient, remoteSize);//如果断点续传没有成功,则删除服务器上文件,重新上传if(result == UploadStatus.Upload_From_Break_Failed){if(!ftpClient.deleteFile(remoteFileName)){return UploadStatus.Delete_Remote_Faild;}result = uploadFile(remoteFileName, f, ftpClient, 0);}}else {result = uploadFile(remoteFileName, new File(local), ftpClient, 0);}return result;}/*** 断开与远程服务器的连接* @throws IOException*/public void disconnect() throws IOException{if(ftpClient.isConnected()){ftpClient.disconnect();}}/*** 递归创建远程服务器目录* @param remote 远程服务器文件绝对路径* @param ftpClient FTPClient对象* @return 目录创建是否成功* @throws IOException*/public UploadStatus CreateDirecroty(String remote,FTPClient ftpClient) throws IOException{UploadStatus status = UploadStatus.Create_Directory_Success;String directory = remote.substring(0,remote.lastIndexOf("/")+1);if(!directory.equalsIgnoreCase("/")&&!ftpClient.changeWorkingDirectory(new String(directory.getBytes("GBK"),"iso-8859-1"))){//如果远程目录不存在,则递归创建远程服务器目录int start=0;int end = 0;if(directory.startsWith("/")){start = 1;}else{start = 0;}end = directory.indexOf("/",start);while(true){String subDirectory = new String(remote.substring(start,end).getBytes("GBK"),"iso-8859-1");if(!ftpClient.changeWorkingDirectory(subDirectory)){if(ftpClient.makeDirectory(subDirectory)){ftpClient.changeWorkingDirectory(subDirectory);}else {System.out.println("创建目录失败");return UploadStatus.Create_Directory_Fail;}}start = end + 1;end = directory.indexOf("/",start);//检查所有目录是否创建完毕if(end <= start){break;}}}return status;}/*** 上传文件到服务器,新上传和断点续传* @param remoteFile 远程文件名,在上传之前已经将服务器工作目录做了改变* @param localFile 本地文件File句柄,绝对路径* @param processStep 需要显示的处理进度步进值* @param ftpClient FTPClient引用* @return* @throws IOException*/public UploadStatus uploadFile(String remoteFile,File localFile,FTPClient ftpClient,long remoteSize) throws IOException{UploadStatus status;//显示进度的上传long step = localFile.length() / 100;long process = 0;long localreadbytes = 0L;RandomAccessFile raf = new RandomAccessFile(localFile,"r");OutputStream out = ftpClient.appendFileStream(new String(remoteFile.getBytes("GBK"),"iso-8859-1"));//断点续传if(remoteSize>0){ftpClient.setRestartOffset(remoteSize);process = remoteSize /step;raf.seek(remoteSize);localreadbytes = remoteSize;}byte[] bytes = new byte[1024];int c;while((c = raf.read(bytes))!= -1){out.write(bytes,0,c);localreadbytes+=c;if(localreadbytes / step != process){process = localreadbytes / step;System.out.println("上传进度:" + process);//TODO 汇报上传状态}}out.flush();raf.close();out.close();boolean result =ftpClient.completePendingCommand();if(remoteSize > 0){status = result?UploadStatus.Upload_From_Break_Success:UploadStatus.Upload_From_Break_Failed;}else {status = result?UploadStatus.Upload_New_File_Success:UploadStatus.Upload_New_File_Failed;}return status;}public static void main(String[] args) {ContinueFTP myFtp = new ContinueFTP();try {System.err.println(myFtp.connect("10.10.6.236", 21, "5", "jieyan"));// myFtp.ftpClient.makeDirectory(new String("歌曲".getBytes("GBK"),"iso-8859-1"));// myFtp.ftpClient.changeWorkingDirectory(new String("歌曲".getBytes("GBK"),"iso-8859-1"));// myFtp.ftpClient.makeDirectory(new String("爱你等于爱自己".getBytes("GBK"),"iso-8859-1"));// System.out.println(myFtp.upload("E:\\yw.flv", "/yw.flv",5));// System.out.println(myFtp.upload("E:\\爱你等于爱自己.mp4","/爱你等于爱自己.mp4"));//System.out.println(myFtp.download("/爱你等于爱自己.mp4", "E:\\爱你等于爱自己.mp4"));myFtp.disconnect();} catch (IOException e) {System.out.println("连接FTP出错:"+e.getMessage());}}}

❸ 如何用Java实现FTP服务器

在主函数中,完成服务器端口的侦听和服务线程的创建。我们利用一个静态字符串变量initDir 来保存服务器线程运行时所在的工作目录。服务器的初始工作目录是由程序运行时用户输入的,缺省为C盘的根目录。 具体的代码如下: public class ftpServer extends Thread{private Socket socketClient;private int counter;private static String initDir;public static void main(String[] args){if(args.length != 0) {initDir = args[0];}else{ initDir = "c:";}int i = 1;try{System.out.println("ftp server started!");//监听21号端口ServerSocket s = new ServerSocket(21);for(;;){//接受客户端请求Socket incoming = s.accept();//创建服务线程new ftpServer(incoming,i).start();i++;}}catch(Exception e){}}

❹ java 怎么写文件到ftp服务器

可以用文件流的方式直接写到服务器,也可以先在本地生成再调用ftp接口上传到服务器

❺ java 实现ftp上传如何创建文件夹

这个功能我也刚写完,不过我也是得益于同行,现在我也把自己的分享给大家,希望能对大家有所帮助,因为自己的项目不涉及到创建文件夹,也仅作分享,不喜勿喷谢谢!

interface:packagecom.sunline.bank.ftputil;importjava.io.BufferedInputStream;importjava.io.BufferedOutputStream;importorg.apache.commons.net.ftp.FTPClient;publicinterfaceIFtpUtils{/***ftp登录*@paramhostname主机名*@paramport端口号*@paramusername用户名*@parampassword密码*@return*/publicFTPClientloginFtp(Stringhostname,Integerport,Stringusername,Stringpassword);/***上穿文件*@paramhostname主机名*@paramport端口号*@paramusername用户名*@parampassword密码*@paramfpathftp路径*@paramlocalpath本地路径*@paramfileName文件名*@return*/(Stringhostname,Integerport,Stringusername,Stringpassword,Stringfpath,Stringlocalpath,StringfileName);/***批量下载文件*@paramhostname*@paramport*@paramusername*@parampassword*@paramfpath*@paramlocalpath*@paramfileName源文件名*@paramfilenames需要修改成的文件名*@return*/publicbooleandownloadFileList(Stringhostname,Integerport,Stringusername,Stringpassword,Stringfpath,Stringlocalpath,StringfileName,Stringfilenames);/***修改文件名*@paramlocalpath*@paramfileName源文件名*@paramfilenames需要修改的文件名*/(Stringlocalpath,StringfileName,Stringfilenames);/***关闭流连接、ftp连接*@paramftpClient*@parambufferRead*@parambuffer*/publicvoidcloseFtpConnection(FTPClientftpClient,,BufferedInputStreambuffer);}impl:packagecom.sunline.bank.ftputil;importjava.io.BufferedInputStream;importjava.io.BufferedOutputStream;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;importorg.apache.commons.net.ftp.FTPClient;importorg.apache.commons.net.ftp.FTPFile;importorg.apache.commons.net.ftp.FTPReply;importcommon.Logger;{privatestaticLoggerlog=Logger.getLogger(FtpUtilsImpl.class);FTPClientftpClient=null;Integerreply=null;@OverridepublicFTPClientloginFtp(Stringhostname,Integerport,Stringusername,Stringpassword){ftpClient=newFTPClient();try{ftpClient.connect(hostname,port);ftpClient.login(username,password);ftpClient.setControlEncoding("utf-8");reply=ftpClient.getReplyCode();ftpClient.setDataTimeout(60000);ftpClient.setConnectTimeout(60000);//设置文件类型为二进制(避免解压缩文件失败)ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);//开通数据端口传输数据,避免阻塞ftpClient.enterLocalActiveMode();if(!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())){log.error("连接FTP失败,用户名或密码错误");}else{log.info("FTP连接成功");}}catch(Exceptione){if(!FTPReply.isPositiveCompletion(reply)){try{ftpClient.disconnect();}catch(IOExceptione1){log.error("登录FTP失败,请检查FTP相关配置信息是否正确",e1);}}}returnftpClient;}@Override@SuppressWarnings("resource")(Stringhostname,Integerport,Stringusername,Stringpassword,Stringfpath,Stringlocalpath,StringfileName){booleanflag=false;ftpClient=loginFtp(hostname,port,username,password);BufferedInputStreambuffer=null;try{buffer=newBufferedInputStream(newFileInputStream(localpath+fileName));ftpClient.changeWorkingDirectory(fpath);fileName=newString(fileName.getBytes("utf-8"),ftpClient.DEFAULT_CONTROL_ENCODING);if(!ftpClient.storeFile(fileName,buffer)){log.error("上传失败");returnflag;}buffer.close();ftpClient.logout();flag=true;returnflag;}catch(Exceptione){e.printStackTrace();}finally{closeFtpConnection(ftpClient,null,buffer);log.info("文件上传成功");}returnfalse;}@OverridepublicbooleandownloadFileList(Stringhostname,Integerport,Stringusername,Stringpassword,Stringfpath,Stringlocalpath,StringfileName,Stringfilenames){ftpClient=loginFtp(hostname,port,username,password);booleanflag=false;=null;if(fpath.startsWith("/")&&fpath.endsWith("/")){try{//切换到当前目录this.ftpClient.changeWorkingDirectory(fpath);this.ftpClient.enterLocalActiveMode();FTPFile[]ftpFiles=this.ftpClient.listFiles();for(FTPFilefiles:ftpFiles){if(files.isFile()){System.out.println("=================="+files.getName());FilelocalFile=newFile(localpath+"/"+files.getName());bufferRead=newBufferedOutputStream(newFileOutputStream(localFile));ftpClient.retrieveFile(files.getName(),bufferRead);bufferRead.flush();}}ftpClient.logout();flag=true;}catch(IOExceptione){e.printStackTrace();}finally{closeFtpConnection(ftpClient,bufferRead,null);log.info("文件下载成功");}}modifiedLocalFileName(localpath,fileName,filenames);returnflag;}@Override(Stringlocalpath,StringfileName,Stringfilenames){Filefile=newFile(localpath);File[]fileList=file.listFiles();if(file.exists()){if(null==fileList||fileList.length==0){log.error("文件夹是空的");}else{for(Filedata:fileList){Stringorprefix=data.getName().substring(0,data.getName().lastIndexOf("."));Stringprefix=fileName.substring(0,fileName.lastIndexOf("."));System.out.println("index==="+orprefix+"prefix==="+prefix);if(orprefix.contains(prefix)){booleanf=data.renameTo(newFile(localpath+"/"+filenames));System.out.println("f============="+f);}else{log.error("需要重命名的文件不存在,请检查。。。");}}}}}@OverridepublicvoidcloseFtpConnection(FTPClientftpClient,,BufferedInputStreambuffer){if(ftpClient.isConnected()){try{ftpClient.disconnect();}catch(IOExceptione){e.printStackTrace();}}if(null!=bufferRead){try{bufferRead.close();}catch(IOExceptione){e.printStackTrace();}}if(null!=buffer){try{buffer.close();}catch(IOExceptione){e.printStackTrace();}}}publicstaticvoidmain(String[]args)throwsIOException{Stringhostname="xx.xxx.x.xxx";Integerport=21;Stringusername="edwftp";Stringpassword="edwftp";Stringfpath="/etl/etldata/back/";StringlocalPath="C:/Users/Administrator/Desktop/ftp下载/";StringfileName="test.txt";Stringfilenames="ok.txt";FtpUtilsImplftp=newFtpUtilsImpl();/*ftp.modifiedLocalFileName(localPath,fileName,filenames);*/ftp.downloadFileList(hostname,port,username,password,fpath,localPath,fileName,filenames);/*ftp.uploadLocalFilesToFtp(hostname,port,username,password,fpath,localPath,fileName);*//*ftp.modifiedLocalFileName(localPath);*/}}

❻ java实现ftp文件操作的方式有哪些

运用类的办法,编程人员能够长途登录到服务器,罗列该服务器上的目录,设置传输协议,以及传送文件。FtpClient类涵 盖了简直一切FTP的功用,FtpClient的实例变量保留了有关树立"署理"的各种信息。下面给出了这些实例变量:public static boolean useFtpProxy这个变量用于标明FTP传输过程中是不是运用了一个署理,因此,它实际上是一个符号,此符号若为TRUE,标明运用了一个署理主机。public static String ftpProxyHost此变量只要在变量useFtpProxy为TRUE时才有用,用于保留署理主机名。public static int ftpProxyPort此变量只要在变量useFtpProxy为TRUE时才有用,用于保留署理主机的端口地址。FtpClient有三种不同方式的结构函数,如下所示:1、public FtpClient(String hostname,int port)此结构函数运用给出的主机名和端口号树立一条FTP衔接。2、public FtpClient(String hostname)此结构函数运用给出的主机名树立一条FTP衔接,运用默许端口号。3、FtpClient()此结构函数将创立一FtpClient类,但不树立FTP衔接。这时,FTP衔接能够用openServer办法树立。一旦树立了类FtpClient,就能够用这个类的办法来翻开与FTP服务器的衔接。类ftpClient供给了如下两个可用于翻开与FTP服务器之间的衔接的办法。public void openServer(String hostname)这个办法用于树立一条与指定主机上的FTP服务器的衔接,运用默许端口号。

❼ 求用java写一个ftp服务器客户端程序。

import java.io.*;import java.net.*;public class ftpServer extends Thread{ public static void main(String args[]){ String initDir; initDir = "D:/Ftp"; ServerSocket server; Socket socket; String s; String user; String password; user = "root"; password = "123456"; try{ System.out.println("MYFTP服务器启动…."); System.out.println("正在等待连接…."); //监听21号端口 server = new ServerSocket(21); socket = server.accept(); System.out.println("连接成功"); System.out.println("**********************************"); System.out.println(""); InputStream in =socket.getInputStream(); OutputStream out = socket.getOutputStream(); DataInputStream din = new DataInputStream(in); DataOutputStream dout=new DataOutputStream(out); System.out.println("请等待验证客户信息…."); while(true){ s = din.readUTF(); if(s.trim().equals("LOGIN "+user)){ s = "请输入密码:"; dout.writeUTF(s); s = din.readUTF(); if(s.trim().equals(password)){ s = "连接成功。"; dout.writeUTF(s); break; } else{s ="密码错误,请重新输入用户名:";<br> dout.writeUTF(s);<br> <br> } } else{ s = "您输入的命令不正确或此用户不存在,请重新输入:"; dout.writeUTF(s); } } System.out.println("验证客户信息完毕…."); while(true){ System.out.println(""); System.out.println(""); s = din.readUTF(); if(s.trim().equals("DIR")){ String output = ""; File file = new File(initDir); String[] dirStructure = new String[10]; dirStructure= file.list(); for(int i=0;i<dirStructure.length;i++){ output +=dirStructure[i]+"\n"; } s=output; dout.writeUTF(s); } else if(s.startsWith("GET")){ s = s.substring(3); s = s.trim(); File file = new File(initDir); String[] dirStructure = new String[10]; dirStructure= file.list(); String e= s; int i=0; s ="不存在"; while(true){ if(e.equals(dirStructure[i])){ s="存在"; dout.writeUTF(s); RandomAccessFile outFile = new RandomAccessFile(initDir+"/"+e,"r"); byte byteBuffer[]= new byte[1024]; int amount; while((amount = outFile.read(byteBuffer)) != -1){ dout.write(byteBuffer, 0, amount);break; }break; } else if(i<dirStructure.length-1){ i++; } else{ dout.writeUTF(s); break; } } } else if(s.startsWith("PUT")){ s = s.substring(3); s = s.trim(); RandomAccessFile inFile = new RandomAccessFile(initDir+"/"+s,"rw"); byte byteBuffer[] = new byte[1024]; int amount; while((amount =din.read(byteBuffer) )!= -1){ inFile.write(byteBuffer, 0, amount);break; } } else if(s.trim().equals("BYE"))break; else{ s = "您输入的命令不正确或此用户不存在,请重新输入:"; dout.writeUTF(s); } } din.close(); dout.close(); in.close(); out.close(); socket.close();}catch(Exception e){ System.out.println("MYFTP关闭!"+e); }}}

❽ 如何用java代码实现ftp文件上传

import java.io.File; import java.io.FileInputStream; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; public class test { private FTPClient ftp; /** * * @param path 上传到ftp服务器哪个路径下 * @param addr 地址 * @param port 端口号 * @param username 用户名 * @param password 密码 * @return * @throws Exception */ private boolean connect(String path,String addr,int port,String username,String password) throws Exception { boolean result = false; ftp = new FTPClient(); int reply; ftp.connect(addr,port); ftp.login(username,password); ftp.setFileType(FTPClient.BINARY_FILE_TYPE); reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); return result; } ftp.changeWorkingDirectory(path); result = true; return result; } /** * * @param file 上传的文件或文件夹 * @throws Exception */ private void upload(File file) throws Exception{ if(file.isDirectory()){ ftp.makeDirectory(file.getName()); ftp.changeWorkingDirectory(file.getName()); String[] files = file.list(); for (int i = 0; i < files.length; i++) { File file1 = new File(file.getPath()+"\\"+files[i] ); if(file1.isDirectory()){ upload(file1); ftp.changeToParentDirectory(); }else{ File file2 = new File(file.getPath()+"\\"+files[i]);

❾ java中怎么实现ftp服务器

我知道apache有个复commons net包,其中的FTPClient类可以实制现客户端和服务之间的文件传输,但是我如果使用这种方式的话,就得将一台服务器上的文件传到我本地,再将这个文件传到另一台服务器上,感觉这中间多了一步操作;

❿ 从JAVA写文件到FTP有几种方法(2)

" );throw ftpprotocolexception; String responseStr = this .getResponseString(); int location = responseStr.lastIndexOf( " , " ); int n = Integer.parseInt(responseStr.substring(location + 1 , responseStr.indexOf( " ) " ))); responseStr = responseStr.substring( 0 ,location); location = responseStr.lastIndexOf( " , " ); int m = Integer.parseInt(responseStr.substring(location + 1 , responseStr.length())); socket = new Socket(serverAddr,m * 256 + n); } if (issueCommand(s) == FTP_ERROR){ MyFtpProtocolException ftpprotocolexception1 = new MyFtpProtocolException(s); throw ftpprotocolexception1; } return socket; } /** * 关闭与FTP服务器的连接 * @throws IOException */ public void closeServer() throws IOException{ socket.close(); socket = null ; super .closeServer(); } /** * 打开与FTP服务器的连接 * @param s FTP服务器地址 * @param i FTP服务器端口 * @throws IOException */ public void openServer(String s, int i) throws IOException{ super .openServer(s,i); serverAddr = s; } } /** * 自定义的FTP异常类 */ class MyFtpProtocolException extends IOException{ MyFtpProtocolException(String s){ super (s); } }编辑推荐Struts查看文件内容功能的方法 每个Web应用程序都是一个独立的Servlet容器,每个Web应用程序分别用一个ServletContext对象。ServletContext对象包含在ServletConfig对象中,调用ServletConfig.getServletContext()方法获取ServletContext对象。调用ServletConfig.getServletContext()方法获取ServletContext对象。1、 getResourcePath 返回一个包含该目录和文件路径名称的Set集合2、 getResource 返回映射到资源上的URL对象。3、 getResourceAsStream 返回连接到某资源上的InputStream对象 InputStreamReader inputReader = new InputStreamReader(input); 需要重新包装成字符处理。


赞 (0)