• 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

  • 相关阅读:
    yum 安装pip
    sed和awk用法
    awk删除最后一个字符
    shell读取文件内容并进行变量赋值
    git 添加、提交、推送
    git 本地代码冲突解决,强制更新
    sys系统模块
    os模块
    time-时间模块
    环境变量的使用
  • 原文地址:https://www.cnblogs.com/bonly-ge/p/7011038.html
Copyright © 2020-2023  润新知