• java 写文件


    FileName为要写入的文件路径
    AppendString为要写入文件的string
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static void AppendFile(String FileName,String AppendString){
      BufferedReader reader = null;
      try {
       reader = new BufferedReader(new InputStreamReader(new FileInputStream(SysConfig.STATIC_INSTALLDATABASEINFO_PATH)));
      } catch (FileNotFoundException e1) {
       e1.printStackTrace();
      }
      StringBuffer buffer = new StringBuffer();
      String line=null;
      try {
       line = reader.readLine();
       while (line != null) {         
                 buffer.append(line);       
                 buffer.append("\n");       
                 line = reader.readLine();  
             }
      } catch (IOException e1) {
       e1.printStackTrace();
      }     
           
      BufferedWriter wr1;
      try {
       wr1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FileName)));
       try {
        wr1.append(buffer);
        wr1.append(AppendString);
        wr1.newLine();
        wr1.flush();
        wr1.close();
       } catch (IOException e) {
        e.printStackTrace();
       }
      } catch (FileNotFoundException e) {
       e.printStackTrace();
      }
     }
     public static void WriteFile(String FileName,String WriteString){
      BufferedWriter wr1;
      try {
       wr1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FileName)));
       try {
        wr1.append(WriteString);
        wr1.newLine();
        wr1.flush();
        wr1.close();
       } catch (IOException e) {
        e.printStackTrace();
       }
      } catch (FileNotFoundException e) {
       e.printStackTrace();
      }
     }
  • 相关阅读:
    Vue-如何实现响应式
    Docker中mysql容器时区问题
    Django格式化日期时,抛出异常ValueError: embedded null byte
    前端报被CORS策略阻止,Django开启跨域解决
    DRF框架之认证、授权和登录
    Django之ALLOWED_HOSTS、LOGGING和多个子应用管理
    DRF框架生成接口文档
    DRF框架之自定义action
    DRF框架之视图集、Routers路由
    DRF框架之Concrete Generic Views
  • 原文地址:https://www.cnblogs.com/kentyshang/p/856981.html
Copyright © 2020-2023  润新知