public static void main(String[] argv) throws Exception { System.setOut(new PrintStream(new FileOutputStream(new File("D:" + File.separator + "txt.txt"))));
System.out.println("今年的中秋节你过的快乐吗?");
}

解决方案 »

  1.   

    我给你发个例子,你看看吧.
    //把session的值存储到记事本里面
    try {
    // 获得tomcat的绝对路径
    HttpSession session = request.getSession();      
    ServletContext  application  = session.getServletContext();    
    String serverRealPath = application.getRealPath("/") ;   
    File file=new File(serverRealPath+"/loginLog.txt");
    if(!file.exists()){
    FileWriter fileWriter = new FileWriter(file,true);
    fileWriter.write("登录时间"+"               "); 
    fileWriter.write("用户名"+"     "); 
    fileWriter.write("\r\n");
    fileWriter.flush();
    fileWriter.close();
    }
    FileWriter fileWriter = new FileWriter(file, true);
    fileWriter.write(Session.getSession("loginTime").toString()+"     "); 
    fileWriter.write(Session.getSession("userId").toString());
    //fileWriter.write(Session.getSession("userName").toString()+"     ");
    //fileWriter.write(Session.getSession("departmentName").toString()+"     ");

    fileWriter.write("\r\n");
    fileWriter.flush();
    fileWriter.close();

    } catch (IOException e) { e.printStackTrace();
    }
    及供参考.
      

  2.   

    告诉你,你的是什么为题,
    (new File("F:"+File.separator+"txt.txt"))
    这里面你用的是中文的 冒号
      

  3.   

    System.setOut(new PrintStream(new FileOutputStream(new File("F:/separatortxt.txt"))));这样的行得通的,要是你的不能生成txt文件,一可能是你路径有问题,二就是里面带有中文的符号,所以你把冒号啊括号啊什么的都检查一遍,绝对OK,我这边我试了下,冇得问题.
      

  4.   

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.PrintStream;
    public class SystemOut1 {
    public static void main()throws Exception{
    System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt"))));
    System.out.println("今年的中秋节你过的快乐吗?");
    }
    }
      

  5.   

    public static void main(String[] args) {
    try {
    System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt"))));
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    System.out.println("今年的中秋节你过的快乐吗?");
    System.out.println("asdadasdddddddddddsadasdasd");
    }运行不压力
      

  6.   

    你这只是new了一个对象,没写任何东西,当然不会产生文件了
      

  7.   

    System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt"))));
    System.out.println("今年的中秋节你过的快乐吗?");
      

  8.   

    没有报错,点击执行就没声了,f盘中也没生成txt.txt文件
      

  9.   

    亲测  负责下面代码到main函数运行try {
    System.setOut(new PrintStream(new FileOutputStream(new File("F:"+File.separator+"txt.txt"))));
    System.out.println("今年的中秋节你过的快乐吗?");
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    问题在"F:"