IO流异常文件日志

来源:互联网 发布:怎样进入人工智能行业 编辑:程序博客网 时间:2024/05/17 01:13
try {
   int[] ints=new int[2];
   System.out.println(ints[3]);
  } catch (Exception e) {
   try {
    PrintStream printStream = new PrintStream("F:\\log.txt");
    Date date=new Date();
    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    printStream.println(simpleDateFormat.format(date));
    System.setOut(printStream);
   } catch (FileNotFoundException e1) {
    throw new RuntimeException("文件创建失败!");
   }
   e.printStackTrace(System.out);
  }
原创粉丝点击