写入日志

来源:互联网 发布:java发短信 编辑:程序博客网 时间:2024/05/17 06:37
  /**
  * 写入日志
  * filePath 日志文件的路径
  * code 要写入日志文件的内容
  */
 public static boolean print(String filePath,String code) {
  try {
   File tofile=new File(filePath);
   FileWriter fw=new FileWriter(tofile,true);
   BufferedWriter bw=new BufferedWriter(fw);
   PrintWriter pw=new PrintWriter(bw);
  
   System.out.println(getDate()+":"+code);
   pw.println(getDate()+":"+code);
   pw.close();
   bw.close();
   fw.close();
   return true;
  } catch (IOException e) {
   return false;
  }
 }
原创粉丝点击