zoukankan      html  css  js  c++  java
  • java 写入文件

    public void writeSqlLogs() throws IOException {
    //创建日志

    String update_sql_file_path="C:\Users\Administrator\Desktop\update_sql.txt";

    String rollbakc_sql_file_path="C:\Users\Administrator\Desktop\rollback_sql.txt";
    FileWriter update_sql_file = null; //log文件1
    FileWriter rollbakc_sql_file = null;//log文件2
    update_sql_file = new FileWriter(update_sql_file_path);//不保留上次记录,想保留上次记录参数设置为(update_sql_file_path,true)
    rollbakc_sql_file = new FileWriter(rollbakc_sql_file_path);//

    String update_sql = "";
    String rollback_sql = "";


    //----code------------------------------

     //写入日志
    update_sql = "-- 更新语句"+" ";
    this.writeLog(update_sql_file, update_sql);
    rollback_sql = " -- 回滚语句"+" ";
    this.writeLog(rollbakc_sql_file, rollback_sql);

    //----code------------------------------

    //关闭日志
    this.logClose(update_sql_file);
    this.logClose(rollbakc_sql_file);
    }

    public void writeLog(FileWriter writer,String log){
    try {
    writer.write(log);
    writer.flush();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    public void logClose(FileWriter writer){
    if(writer!=null){
    try {
    writer.close();
    } catch (IOException e) {
    System.out.println(this+",关闭日志失败");
    e.printStackTrace();
    }
    }
    }

  • 相关阅读:
    fullCalendar改造计划之带农历节气节假日的万年历(转)
    Linked List Cycle
    Remove Nth Node From End of List
    Binary Tree Inorder Traversal
    Unique Binary Search Trees
    Binary Tree Level Order Traversal
    Binary Tree Level Order Traversal II
    Plus One
    Remove Duplicates from Sorted List
    Merge Two Sorted Lists
  • 原文地址:https://www.cnblogs.com/caer/p/6051150.html
Copyright © 2011-2022 走看看