Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write java resource in src directory

I am making a (tile)level editor using java and eclipse as IDE. I am using getResourceAsStream to load tilemap. And this code to write map back.

URL resourceUrl = getClass().getResource(FILENAME);
File file = new File(resourceUrl.toURI());
OutputStream output = new FileOutputStream(file);

It works fine, but the problem, that i have two direcotries bin/ and src/. Directory bin/ will be generated by eclipse. So i want edit files in src dir. Unfortunately getResource() works with bin/ direcoty. Moreover, if i rebuild a project, all changes on map will be deleted. So i just want to edit tilemaps in src/ folder. How can i achieve that?

I would like to avoid hardcoding some absoulte paths.

like image 459
AvrDragon Avatar asked Jan 30 '26 04:01

AvrDragon


1 Answers

Eclipse starts project with workdir = project dir by default, so src is right under workdir. Use relative path

File file = new File("src/fileName");
like image 91
Evgeniy Dorofeev Avatar answered Feb 01 '26 16:02

Evgeniy Dorofeev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!