简体   繁体   English

我在哪里可以找到打印流输出到的文本文件?

[英]Where do i find the text file that print stream outputs to?

This is my code for writing to a file using print stream in java 这是我使用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();
        }

My question is after I execute this piece of code, where can I find hi.txt in eclipse? 我的问题是执行这段代码后,在eclipse中哪里可以找到hi.txt? Usually when I am working with text files, the text file appears under JRE system Library. 通常,当我使用文本文件时,该文本文件会出现在JRE系统库下。 In this case, it doesn't 在这种情况下,它不会

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

Besides @Eran's answer, you can just print the absolute path of a File object if you are wondering where it is on the file system. 除了@Eran的答案,如果您想知道File对象在文件系统中的位置,则可以仅打印File对象的绝对路径。

 File f = new File( "hi.txt" );
 System.out.println(f.getAbsoluteFile());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM