1. 程式人生 > >將指定內容寫入目標文件(日誌)

將指定內容寫入目標文件(日誌)

stat null path oid reat clip 指定 lis post

public static void logResult(String str) {      //str 要寫入的內容
  FileWriter writer = null;
  try {
    // String s = AlipayConfig.log_path + "//log//"+"alipay_log_" + System.currentTimeMillis()+".txt";
    String s = "F://myeclipse85//log//"+System.currentTimeMillis()+".txt";
    File file = new File(s);
    if(!file.exists()){
      file.createNewFile();
    }
    writer = new FileWriter(file);
    writer.write(str);
  } catch (Exception e) {
    e.printStackTrace();
  } finally {
    if (writer != null) {
      try {
        writer.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }

}

將指定內容寫入目標文件(日誌)