文件夹2. 文件夹创建、删除的操作
servlet层
1 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 2 throws ServletException, IOException { 3 req.setCharacterEncoding("utf-8"); 4 resp.setCharacterEncoding("utf-8"); 5 resp.setContentType("text/html;charset=utf-8"); 6 PrintWriter out=resp.getWriter(); 7 JSONObject data=getJsonObject(req); 8 String filesPath=data.getString("filesPath"); 9 boolean res=false; 10 if(filesPath!=null) { 11 File file=new File(filesPath); 12 // res=createFolder(filesPath); 13 res=deleteFolder(filesPath); 14 } 15 16 } 17 18 private boolean deleteFolder(String filesPath) { 19 boolean res=false; 20 File file=new File(filesPath); 21 if(file.exists() && file.isDirectory()) { 22 res=file.delete(); 23 } 24 return res; 25 } 26 27 private boolean createFolder(String filesPath) { 28 boolean res=false; 29 File file=new File(filesPath); 30 res=file.mkdir(); 31 return res; 32 } 33 34 private JSONObject getJsonObject(HttpServletRequest req) { 35 StringBuffer json=new StringBuffer(); 36 String lineString=null; 37 BufferedReader reader; 38 JSONObject data=null; 39 try { 40 reader = req.getReader(); 41 while((lineString=reader.readLine())!=null) { 42 json.append(lineString); 43 } 44 data=JSONObject.fromObject(json.toString()); 45 } catch (IOException e) { 46 e.printStackTrace(); 47 } 48 return data; 49 }