求大神帮解决ftp上传图片到服务器的问题

crazyly_k 2015-04-21 10:15:08
public boolean upload(File file,XML xml1) throws Exception{
try {
bstate=0;
while(ftp==null || bstate<2)
{
sleep(500);
bstate=connect(xml1);
if(ftp==null || bstate<2){
System.out.println("连接服务器失败,请检查服务器是否开启!");
}
}
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,xml1);
ftp.changeToParentDirectory();
}else{
File file2 = new File(file.getPath()+"\\"+files[i]);
FileInputStream input = new FileInputStream(file2);
ftp.storeFile(file2.getName(), input);
input.close();
}
}
}else{
File file2 = new File(file.getPath());
FileInputStream input = new FileInputStream(file2);
ftp.storeFile(file2.getName(), input);
bsc=true;
input.close();
}

ftp.logout();
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
ftp.disconnect();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
return bsc;
}

走到红色代码处,如果服务器断开了就没反应也不报错,调试也不往下走,这是什么原因?
...全文
160 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
crazyly_k 2015-04-21
  • 打赏
  • 举报
回复
那我需要怎么捕获这个异常呢?
zx8813443 2015-04-21
  • 打赏
  • 举报
回复
也有可能抛出的是throwable类型的错误

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧