I***e 发帖数: 1136 | 1 I have a few classes accessing a "data.txt" file. I want to create a .jar file
and package everything in. However, how do I point to the data.txt file
inside the jar?
If it is outside I can easily use something like
FileWriter fw=new FileWriter("C:\\data.txt");
Now what should I do?
Thanks.
-iCare- |
g**********y 发帖数: 14569 | 2 Use getClass().getResource("/data.txt"); if data.txt is in the top level of
JAR. If you want to visit it from same level of class, then getClass().
getResource("data.txt");
file
【在 I***e 的大作中提到】 : I have a few classes accessing a "data.txt" file. I want to create a .jar file : and package everything in. However, how do I point to the data.txt file : inside the jar? : If it is outside I can easily use something like : FileWriter fw=new FileWriter("C:\\data.txt"); : Now what should I do? : Thanks. : -iCare-
|
I***e 发帖数: 1136 | 3 Great! Thanks.
【在 g**********y 的大作中提到】 : Use getClass().getResource("/data.txt"); if data.txt is in the top level of : JAR. If you want to visit it from same level of class, then getClass(). : getResource("data.txt"); : : file
|