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

Posted 流去

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将指定内容写入目标文件(日志)相关的知识,希望对你有一定的参考价值。

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

}

以上是关于将指定内容写入目标文件(日志)的主要内容,如果未能解决你的问题,请参考以下文章