简体   繁体   中英

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.

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.

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.

请尝试以下方法:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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