import java.io.*;
public class haha { 
  public static void main(String[] args) {
    PrintStream ps = null;
    try {
      FileOutputStream fos = 
              new FileOutputStream("e:\\bak\\log.dat");//在指定路径下生成文件,为什么我把文件夹bak去掉能生成
                                                                 log.dat前面加bak就实例不了,只有ECLIPSE下输出
      ps = new PrintStream(fos);
    } catch (IOException e) {
      e.printStackTrace();
    }
    if(ps != null){
      System.setOut(ps);
    }
    int ln = 0;
    for(char c = 0; c <= 60000; c++){
      System.out.print(c+ " ");
      if(ln++ >=100){ System.out.println(); ln = 0;}
    }
  }
}

解决方案 »

  1.   

    请确定你的e分区存在bak文件夹...不存在请创建
      

  2.   

    不过,System被重定向后,找不到输出文件竟然还是会输出到控制台来!不错!
      

  3.   

    必须先创建bak文件夹,如果没有会出现:java.io.FileNotFoundException: e:\bak\log.dat (系统找不到指定的路径。)
    只不过你在程序中打印的数据太多了,把异常给掩盖了
      

  4.   

    因为bak路径没有。FileOutputStream能够直接创建log.dat文件,但条件是指定的路径必须是存在的。