Hi everyone, i will provide the guide on how to bundle and handle the resource in the jar file.
1) First, create a resource directory under the build path.
2) You need to put your resource(eg txt file) into that resource directory.
3)When you build your shadow jar the resource is supposed to be inside(to check just open it with winrar).
4) To access this resource file, you will first need to create a InputStream and direct it to your resource directory.
5) Next, create a InputStreamReader to store the content of your inputStream. (You cannot use FileReader because the resource will be inside your jar file and your jar file is like a ZIP file.)
6)Next, once the data is stored into your InputStreamReader you will need a BufferedReader to decrypt and read the content like how you read a normal file using file reader.
Note: You cannot write to the resource file inside the jar file, it is meant to be read only. If you want, you can copy the file inside the resource of the jar and save it outside the jar file.
Hi everyone, i will provide the guide on how to bundle and handle the resource in the jar file.
1) First, create a resource directory under the build path. 2) You need to put your resource(eg txt file) into that resource directory.
3)When you build your shadow jar the resource is supposed to be inside(to check just open it with winrar). 4) To access this resource file, you will first need to create a InputStream and direct it to your resource directory. 5) Next, create a InputStreamReader to store the content of your inputStream. (You cannot use FileReader because the resource will be inside your jar file and your jar file is like a ZIP file.) 6)Next, once the data is stored into your InputStreamReader you will need a BufferedReader to decrypt and read the content like how you read a normal file using file reader.
Note: You cannot write to the resource file inside the jar file, it is meant to be read only. If you want, you can copy the file inside the resource of the jar and save it outside the jar file.