Hi, I have a question about how confluence storing package files.
In example i have a webwork action MyAction and some file named as myfile.txt
package for this objects is
<root>/src/main/java/com/example/actions/MyAction.java
<root>/src/main/resources/text/myfile.txt
How I can refer to myfile.txt in MyAction?
Community moderators have prevented the ability to post new answers.
Assuming you are writing a Confluence plugin, and the myfile.txt is included in your plugin jar, you can use the MyAction's ClassLoader to get the contents of the text file.
Something like this:
InputStream myFile = this.getClass().getClassLoader().getResourceAsStream("text/myfile.txt");
This is correct. However I would add that if you are using this method to load a file, most classloaders will cache the contents of the file in memory for the lifetime of the classloader. We've run into this problem a few times in Confluence where we use resource streams to load large data files that we only need during startup.
If you're worried about the object you're loading being cached, you can instead use the getResource() method to return a URL to the file, then open that URL independently.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.