Commit 872c1927 authored by 刘文胜's avatar 刘文胜

ftp 工具类异常处理

parent 8b45c19a
......@@ -106,12 +106,9 @@ public class FtpUtil {
System.err.println("FTP server refused connection.");
System.exit(1);
}
} catch (SocketException e) {
} catch (Throwable e) {
e.printStackTrace();
logger.error(e.toString());
} catch (IOException e) {
logger.error(e.toString());
e.printStackTrace();
}
return ftpClient;
}
......@@ -121,8 +118,9 @@ public class FtpUtil {
*/
public List<String[]> readCSVFile(String fileName) {
List<String[]> list = new ArrayList<String[]>();
FTPClient ftpClient = null;
try {
FTPClient ftpClient = this.getFTPClient();
ftpClient = this.getFTPClient();
InputStream csv = ftpClient.retrieveFileStream(getFileDir
+ fileName);
if (csv == null) {
......@@ -135,11 +133,16 @@ public class FtpUtil {
CSVReader csvReader = new CSVReader(inputStreamReader);
list = csvReader.readAll();
csvReader.close();
ftpClient.disconnect();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (Throwable e) {
e.printStackTrace();
} finally{
if(ftpClient!=null){
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return list;
}
......@@ -148,8 +151,9 @@ public class FtpUtil {
* 移动文件
*/
public void moveFile(String fileName) {
FTPClient ftpClient = null;
try {
FTPClient ftpClient = this.getFTPClient();
ftpClient = this.getFTPClient();
// 新的文件名
String suffix = fileName.substring(fileName.lastIndexOf("."));
......@@ -159,9 +163,16 @@ public class FtpUtil {
ftpClient.rename(getFileDir + fileName, getFileHistoryDir
+ newFileName);
ftpClient.disconnect();
} catch (IOException e) {
} catch (Throwable e) {
e.printStackTrace();
}finally{
if(ftpClient!=null){
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
......@@ -183,7 +194,7 @@ public class FtpUtil {
CSVWriter.NO_QUOTE_CHARACTER);
}
} catch (IOException e) {
} catch (Throwable e) {
e.printStackTrace();
}
return writer;
......@@ -204,7 +215,7 @@ public class FtpUtil {
ftpClient.storeFile(putAddFileName, addInputStream);
ftpClient.storeFile(putUpdateFileName, updateInputStream);
} catch (IOException e) {
} catch (Throwable e) {
e.printStackTrace();
logger.error(e.toString());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment