在Java IDE中使用IO Streams时,文件将位于哪里? [英] Where the file will be located while using IO Streams in Java In Eclipse IDE?

查看:108
本文介绍了在Java IDE中使用IO Streams时,文件将位于哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文件中打印输出。我使用 PrintWriter IO流将数据添加到文件。当我想检查它,我不知道文件所在的位置。我正在使用Eclipse IDE。

I want to print the output in a file. I am using PrintWriter IO stream to add the data to file. When I want to check it, I don't know where the file is located. I am using Eclipse IDE.

PrintWriter writer=new PrintWriter("output.txt","UTF-8");
writer.println("Barcode Reader");

所以可以指出我的文件位于哪里?

So can any one point me to where the file will be located?

推荐答案

当我切换到使用Eclipse时,我最初遇到这个问题。当前的相对路径设置为项目目录。以下代码段将会更好地解释这一点。

I had this problem initially when I switched to using Eclipse. The current relative path is set to the project directory. The following code snippet will explain this better.

Path currentRelativePath = Paths.get("");
String myPath = currentRelativePath.toAbsolutePath().toString();
System.out.println("Current relative path is: " + myPath);

请注意,Path路径((复数))中的get方法接收到Path对象。它们位于java.nio.file中。

Note that the Path object is received from a get method in Paths((plural)). They are located in java.nio.file.

有关此信息的更多信息,请参见路径操作页面

Further information about this can be found in the Path Operations page.

这是否解决了您的问题?

Does that solve your problem?

这篇关于在Java IDE中使用IO Streams时,文件将位于哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆