您的位置:首页 > 其它

检测文件夹&文件是否存在

2016-04-14 11:15 323 查看
public void checkappfile(HttpServletRequest req, HttpServletResponse resp) throws IOException{

String fname="aa.apk,bb.ipa,cc.png";
String [] filename=fname.split(",");
String url = req.getRealPath("/");

File root = new File(url);
File[] files = root.listFiles();
boolean app = false;
for(File file:files){
if(file.getName().equals("app")){
app=true;
break;
}
}
JSONObject jsonObject=new JSONObject();String code="00";
if(app){
String result = "";
boolean msg = false;
try {
File root1 = new File(url+"app");
File[] fileapp = root1.listFiles();
for(File file:fileapp){
for(int i=0;i<filename length="" i="" msg="filename[i].equals(file.getName());" if="" filename="" i="" equals="" file="" getname="" result="result+filename[i]+',';" result="result.substring(0,result.length()-1);" if="" result="" length="">35){
code="02";msg=true;
}else{
code="01";msg=false;
}
} catch (Exception e) {
e.printStackTrace();
}
jsonObject.put("code",code);
jsonObject.put("isSuccess",msg);
jsonObject.put("msg",result);
System.out.println(jsonObject.toString());
resp.getWriter().append(jsonObject.toString());
}else{
jsonObject.put("code","00");
jsonObject.put("isSuccess",app);
jsonObject.put("msg","没有找到对应的文件夹");
System.out.println(jsonObject.toString());
resp.getWriter().append(jsonObject.toString());
}

}
返回结果:{"code":"00","isSuccess":false,"msg":"没有找到对应的文件夹"}{"code":"01","isSuccess":false,"msg":"aa.apk"}{"code":"02","isSuccess":true,"msg":"aa.apk,bb.ipa,cc.png"}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: