首页 > 代码库 > jsp文件系统
jsp文件系统
属性 | 方法 |
获取根目录 | request.getServletContext().getRealPath("/"); |
创建目录 | File file= new File(path); if(!file.exists()){ file.mkdirs(); } |
写文件 | File file =new File("文件路径"); OutputStreamWriter osw =new OutputStreamWriter(new FileOutputStream(file,"是否追加"),"字符编码"); osw.write("写入内容"); osw.flush(); osw.close(); |
读文件 | File file =new File("文件路径"); InputStreamReader isr=new InputStreamReader(new FileInputStream(file),"字符编码"); StringBuider sb= new StringBuider(); while(isr.ready()){ sb.append((char)isr.read()); } isr.close(); |
删除文件 | File file =new File("path");//有没有引号 file.delete(); |
静态化技术 | URL url =new URL ("htpp://www.rsseasy.com"); HttpURLConnection connection =(HttpURLConnection)url.openConnection(); BufferedReader in =new BufferedReader(new InputStreanReader(connection.getInputStream(),"utf-8")); StringBuffer buffer =new StringBuffer(); String line = ""; while((line=in.readLine())!=null){ buffer.append(line); } File file =new File("path"); OutputStreamWrite osw =new OutputStreamWrite(new FileOutputStream(file,file),"utf-8"); osw.write(buffer.toString()); osw.flush(); osw.close();
|
d
jsp文件系统