java - Read relative path (outside class path) using main and test classes -


i have project structure

data_folder/ myproject     module1         main/java         test/java         pom.xml     module2     ... pom.xml 

i access data_folder using both test , main classes.

in test classes, it's possible using

new file("data_folder/myfile.txt") 

but in main classes, it's possible using

new file("../data_folder/myfile.txt") 

these files have outside class path because they're editable. there better way this?

the common way pass in full location of data_folder parameter when start programs/tests:

-dfiles_location=/somelocation/data_folder

then access , create files this:

string root_dir = system.getproperty("files_location"); file myfile = new file(rootdir+file.separator+"myfile.txt")

then doesn't matter if it's relative path or not - point input/data files are.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -