0

这是我在java中使用打印流写入文件的代码

PrintStream stream = null;
        try {
             stream = new PrintStream(new File("hi.txt"));
            stream.println("hi my name is chris");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally{
            stream.close();
        }

我的问题是在我执行了这段代码之后,在eclipse中哪里可以找到hi.txt?通常当我处理文本文件时,文本文件出现在 JRE 系统库下。在这种情况下,它不

4

2 回答 2

3

它应该在您正在运行的 Eclipse 项目的文件夹中创建。

于 2014-08-03T02:26:47.093 回答
2

除了@Eran 的答案,如果您想知道 File 对象在文件系统上的位置,您可以只打印它的绝对路径。

 File f = new File( "hi.txt" );
 System.out.println(f.getAbsoluteFile());
于 2014-08-03T02:36:50.273 回答