Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to read folders and subfolders from resource folder and read all json files from folders and its subfolders and convert into one property file.

Below code is to read files from resource folder. Eg: resources/channel/

It will not read files if the channel has some sub folder.

What I have tried:

Java
public void loadFile() throws IOException {
            String folder = "/channel/sms";
            List<String> files = IOUtils.readLines(getClass().getClassLoader().getResourceAsStream(folder), Charsets.UTF_8);
            System.out.println(JSONUtil.toJSON(files));

        }
Posted
Updated 14-Feb-18 19:30pm
v2
Comments
Richard MacCutchan 14-Feb-18 4:25am    
You just need to read each line of the json file and strip out the newline characters.
Anjanaa R 14-Feb-18 5:54am    
I want to use class loader for reading files and directories.
Property file key should be file name and value should be json string.
Richard MacCutchan 14-Feb-18 6:51am    
So what is your problem?
Anjanaa R 15-Feb-18 1:28am    
My above code will read files from one folder(Eg:channel).If channel has some folder it will not read files. I want to read channel folder also
Updated the ques.
Richard MacCutchan 15-Feb-18 4:51am    
What is the structure of the channel folder, and what results do you get when you try to list its contents?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900