Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java workspace and file path

I have a probably easy to solve problem. I am having a folder in my project and want to get it using the relative path:

new File("/folder")

this gives me FileNotFoundException

if I try like this

new File("d:/workspace/project/folder")

it works

I suspect that it does not work because of this: new File("").getAbsolutePath() returns : D:\eclipse So not the path of the workspace.

Am I doing something wrong or do I need to change some settings in eclipse

like image 974
hhh3112 Avatar asked Dec 15 '22 11:12

hhh3112


2 Answers

Don has pointed that you use a absolute path. That is the problem.

By default the working directory in Eclipse is the path of the project where is the program that you execute.

You can always know the working directory by displaying this property :

System.out.println(System.getProperty("user.dir"));
like image 198
mki Avatar answered Dec 28 '22 07:12

mki


Just found my answer in Run Cofigurations like djna suggested, but not in the Environment Tab but in the Arguments Tab. There is a working directory section in which d:\eclipse was set and which needed to be set to ${workspace_loc:myproject}

like image 21
hhh3112 Avatar answered Dec 28 '22 08:12

hhh3112