If you want to read a file called "readme.txt" which was kept under /src/resources/, use below piece of code to achieve this task.
InputStream stream = getClass().getResourceAsStream("<file-to-read>");
Here, It could be:
InputStream stream = getClass().getResourceAsStream("/readme.txt");
A good practice is to follow convention, For example, if your source code is under /src/main/java/com/test/mytest/Test.java Then your resource should be in location /resource/com/test/myTest/<Your File>
Then you can use something like:
InputStream in = Test.class.getResourceAsStream("<Your File>");
2) You can put a file in the repository (Any repository location is a file) and use Node data as stream to read.
then use following code,
InputStream in = node.getNode("jcr:content").getProperty("jcr:data").getStream();
No comments:
Post a Comment
If you have any doubts or questions, please let us know.