Joe
Joe

Reputation: 15

Fileoutputstream in eclipse. relative path

is there a way to save a .txt file in eclipse?

Currently I'm doing:

FileOutputStream fout = new FileOutputStream("C:\\Users\\xxxx\\mytxtfile.txt", false);

I want it to be in the eclipse folder from the project and not an absolute path.

Upvotes: 1

Views: 1936

Answers (3)

Manish Kumar
Manish Kumar

Reputation: 31

Try the following:

PdfWriter.getInstance(document, newFileOutputStream("C:/Users/xxxx/mytxtfile.txt",false));

Upvotes: 0

Thijs Steel
Thijs Steel

Reputation: 1272

try this

FileOutputStream fout = new FileOutputStream("mytxtfile.txt", false);

If you want to use a folder within the project root I recommend this:

File root = new File("yourfolder");
root.mkdir(); //this makes sure the folder exists
File file = new File(root,"mytextfile.txt");
FileOutputStream fout = new FileOutputStream(file, false);

To get the install location of eclipse for eclipse 3.3 (i don't know why you would do this, but still) System.getProperty("eclipse.home.location");

For newer eclipse versions i don't really know.

Upvotes: 2

Audrius Meškauskas
Audrius Meškauskas

Reputation: 21748

You can set any initial folder you want in the Eclipse app launch configuration. It is the project root by default but this is not ideal; best is to use some folder like 'run' inside the project that you can add to .gitignore.

Then just empty path (new File("")) resolves to that folder, and you can also specify sub-path if required.

Upvotes: 1

Related Questions