| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 
 | ```
 
 
 ## 从 FTP 中下载文件到本地
 ```java
 
 import sun.net.ftp.FtpClient;
 
 
 
 
 
 public void static main(String arg[]){
 
 FtpClient ftp = connectFTP(ip,21,userName,password);
 List<String> list = download(filePath + fileName, ftp);
 for(int i = 0; i<list.size(); i++){
 
 sout(list.get(i));
 
 
 }
 try {
 ftp.close();
 } catch (IOException e) {
 e.printStackTrace();
 }
 }
 
 
 public static List<String> download(String ftpFile, FtpClient ftp) {
 List<String> list = new ArrayList<String>();
 String str = "";
 InputStream is = null;
 BufferedReader br = null;
 try {
 
 is = ftp.getFileStream(ftpFile);
 
 br = new BufferedReader(new InputStreamReader(is,"GBK"));
 while((str=br.readLine())!=null){
 list.add(str);
 }
 br.close();
 }catch (FtpProtocolException e) {
 e.printStackTrace();
 } catch (FileNotFoundException e) {
 e.printStackTrace();
 } catch (IOException e) {
 e.printStackTrace();
 }
 return list;
 }
 
 |