检测文件夹&文件是否存在
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"}
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"}
相关文章推荐
- 获取网页数据的例子
- Can not find the tag library descriptor for "http://www.springframework.org/security/tags"
- Linux服务器配置代理服务器
- jboss ejb 简单实例
- 转载:Oracle连接方式(dispatchers 设置)
- C++中时间延迟的几种方法
- 8天学通MongoDB——第三天 细说高级操作
- C++ ofstream和ifstream详细用法
- PHP抓取淘宝商品的用户晒单评论+图片+搜索商品列表实例
- wordpress数据库结构及表说明
- 解决 tempdb 中磁盘空间不足的问题
- wordpress数据库结构及表说明
- 鼠标点击右键,反应慢,解决方法!
- SGU 109 Magic of David Copperfield II(构造)
- 双目视觉学习笔记
- Unirest-拼装http请求发送rest接口
- 20135220谈愈敏Linux Book_4
- IntelliJ IDEA 控制台中文乱码解决方案
- Linux chmod命令修改文件与文件夹权限的命令附实例
- IntelliJ IDEA 控制台中文乱码解决方案