将指定内容写入目标文件(日志)

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();
      }
    }
  }

}

posted @ 2018-03-27 15:26  流去  阅读(147)  评论(0编辑  收藏  举报