首页 > 代码库 > java读取FTP服务器上gz文件

java读取FTP服务器上gz文件

FTPClient client = new FTPClient();
client.connect(CREDITDATA_FTP_IP, CREDITDATA_FTP_PORT);
client.login(FTP_USERNAME, FTP_PASSWORD);
client.changeWorkingDirectory("/out");
client.enterLocalPassiveMode();         //打开本地被动模式
client.setFileType(FTPClient.BINARY_FILE_TYPE);     //设置传输方式为二进制
client.configure(new FTPClientConfig("UNIX"));      //设置Unix时间戳解析方式
client.setControlEncoding("UTF-8");
stream = new GZIPInputStream(client.retrieveFileStream(fileName));
aiStream = new ArchiveStreamFactory().createArchiveInputStream("tar", stream);
TarArchiveEntry entry = null;
while((entry = (TarArchiveEntry)aiStream.getNextEntry())!=null){
     if(entry.getName().endsWith("/")){  //跳过目录
        continue;
      }
      reader = new BufferedReader(new InputStreamReader(aiStream,"UTF-8"));
      String line = null;
      while ((line = reader.readLine()) != null) {
          parseLine(line);
    }
}

 

java读取FTP服务器上gz文件