zoukankan      html  css  js  c++  java
  • 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();
      }
     }
  • 相关阅读:
    我国大部分地区今晚将上演红色月全食美景[2007828]
    n阶汉诺塔问题(Hanoi)
    NBear中使用WhereClip表示in查询的问题
    web性能测试分析理论篇
    Net类库一览 转
    使用ASP.Net Forms模式实现WebService身份验证
    2005数据源的相关数据绑定
    单位分级,涵闸和人员绑定到树
    ajax,js文件中中文显示成乱码的问题
    WinFom应用程序数据操作技巧
  • 原文地址:https://www.cnblogs.com/kentyshang/p/856981.html
Copyright © 2011-2022 走看看