About IO

I have the following project's structure:

br.com.test.cod

br.com.test.resources

I have a class inside cod "Test.java" and I have a file inside resources "test.properties".

I'm trying to write in test.properties with my class "Test.java".

How can I get this file with no absolute path?

This code :

"File file = new File("br\\com\\test\\resources\test.properties");"

is not working.

Thanks in advance!!

Gin

[473 byte] By [Gina] at [2007-10-3 3:34:58]
# 1

File file = new File(".\\resources\\test.properties");

and I would recommend using ClassLoader.getResource().

Example (inside Test.java):

getClass().getClassLoader().getResource("resources/test.properties");

lfschucka at 2007-7-14 21:29:36 > top of Java-index,Java Essentials,New To Java...
# 2

Ifschuck,

the first way is not working!!

The second way I've already done. But with this way I can get the stuffs inside, but I can't get the place where the file is. I need the right place because another moment I'll use the same file with the new information, undestood?

Thanks!!

Gina at 2007-7-14 21:29:36 > top of Java-index,Java Essentials,New To Java...
# 3

the first method have to work, if you are acessing a file which is not inside a JAR/ZIP file, of course, but I believe it's your case...

I believe that it's not working because you had a typo on your path:

File file = new File("br\\com\\test\\resources\ >>> \ <<< test.properties");

the marked '\' is missing. it was not detected as an error because the next letter is 't', and '\t' means tabulation. even if you include it, it will not work because the path is not correct as relative path.

try the exact code I posted above... It should work! ;-)

lfschucka at 2007-7-14 21:29:36 > top of Java-index,Java Essentials,New To Java...
# 4
Here has a java IO tutorial,help it usefu to youl http://www.developerzone.biz/index.php?option=com_content&task=view&id=156&Itemid=36
hitentirea at 2007-7-14 21:29:36 > top of Java-index,Java Essentials,New To Java...