try {Properties ftpProperties=new Properties();ftpProperties.load(new FileInputStream(new File(this.getClass().getResource("/").getPath()+"ftp.properties")));ftpHost=ftpProperties.getProperty("ftp.host");ftpPort=Integer.parseInt(ftpProperties.getProperty("ftp.port"));ftpUserName=ftpProperties.getProperty("ftp.userName");ftpPassword=ftpProperties.getProperty("ftp.password");ftpPath=ftpProperties.getProperty("ftp.year_path");ftpLocalPath=ftpProperties.getProperty("ftp.year_localpath");new File(ftpLocalPath).mkdirs();ftpClient = FTPUtil.getFTPClient(ftpHost, ftpPassword, ftpUserName,ftpPort);// ftpClient.setControlEncoding("GBK"); // 中文支持ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);ftpClient.enterLocalPassiveMode();ftpClient.setDataTimeout(1000*60);ftpClient.setBufferSize(1024); ftpClient.changeWorkingDirectory(ftpPath);FTPFile[] files=ftpClient.listFiles();for(FTPFile ftpFile:files){String localfileName=ftpLocalPath+new String(ftpFile.getName().getBytes("ISO-8859-1"),"GBK");localFile=new File(localfileName);if(new File(localfileName).exists()){continue;}fos = new FileOutputStream(localfileName);ftpClient.retrieveFile(ftpFile.getName(), fos); fos.close(); in = new FileInputStream(localFile);//importTitele(in,errorList);importDataYear(in,errorList);}} catch (FileNotFoundException e) {e.printStackTrace();localFile.delete();} catch (SocketException e) {e.printStackTrace();localFile.delete();} catch (IOException e) {e.printStackTrace();localFile.delete();} catch (Exception e) {e.printStackTrace();localFile.delete();}}
POI操作Excel、
最新推荐文章于 2023-02-19 11:56:48 发布