0

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?

Adam Michalik
  • 9,678
  • 13
  • 71
  • 102

5 Answers5

1

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);

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?

Debosmit Ray
  • 5,228
  • 2
  • 27
  • 43
  • Ya thank you. But the data are not printing in the file for the same code can you say why? – Keerthilal Haridass Jan 22 '16 at 07:51
  • I will point you to [this post](http://stackoverflow.com/questions/11496700/how-to-use-printwriter-and-file-classes-in-java) to see if that solves your problem. Let me know if you still have issues. – Debosmit Ray Jan 22 '16 at 08:07
0

It will be present in your project's root folder. Just open your project folder from your workspace using Explorer and it will be there.

Mujtaba
  • 143
  • 1
  • 8
0

With a filename like "output.txt" it will be placed into the current working directory.

Unless you specify otherwise, in Eclipse that will be the root directory of your project.

You may have to click "Refresh" for it to show up in the File Explorer.

Thilo
  • 257,207
  • 101
  • 511
  • 656
0

If you give you file name directly like C:\java\workspace\ocpjp7 (a Windows directory) or /home/nblack/docs (the docs directory of user nblack on UNIX), you can find your file in those directories. But if you don't give the full path, it will be in your current working directory.

"output.txt" -> root

"src/resources/output.txt" -> in resources package

John Lash
  • 114
  • 1
  • 4
0

At first you should create this file with File in directory you want.Next step to write data into the file. Your file will be located in directory you want , you set when file has created. Also check this class FileInputStream

DmitriyKhirniy
  • 245
  • 1
  • 7