Hi
Please red the following article:-
Link:- http://www.wemblog.com/2011/10/how-to-read-external-file-in-cq.html (create a custom component/service to read file from FileSystem or read it from JCR after bring it to JCR)
How to read an external file in CQ
Use Case: You want to read something from external file
Solution : There are multiple ways you can do this I will mentioned two of them here,
1) You can put them under /resources folder under /src/main for example if you want to read a file called "test.txt" then you can put file under /src/resources/<any-sub-foler>/<file-to-read>
Then use following code to read file
InputStream stream = getClass().getResourceAsStream("<file-to-read>");
in above case it would be InputStream stream = getClass().getResourceAsStream("/test.txt");
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 file in repository (Any repository location is file) and use Node data as stream to read.
then use following code,
InputStream in = node.getNode("jcr:content").getProperty("jcr:data").getStream();
Another reference article :- https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html
//Uploading of images from FileSystem and keeping it in JCR.
I hope this would help you.
Thanks and Ragards
Kautuk Sahni