I want to read this JSON file - '/Users/test/dos-2018-03-02-22-23/report.json'. But I do not know the exact timestamp while I am reading it, hence I need a regex for the dos-* folder while reading it.
To read file I am doing this :
JSONObject jsonObject = (JSONObject) parser.parse(new FileReader(FILE_PATH));
Now the folder path keeps changing [assume there will be only one though], but I know it starts with 'dos-'. So How do I use this regex pattern in the path ?
I have tried using pathmatcher, but it can be used to match a path that I know I guess.
dosReportFilePath = "/Users/test/";
dosReportFileName = "/report.json"
PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:"+dosReportFilePath+"/dos-*/"+dosReportFileName);
I am not sure how to use it in FileReader. Any help to achieve this will be greatly appreciated.
Found one solution :
I can read all the directories inside dosReportFilePath to get the folder name starting with 'dos-' I guess.[Java, List only subdirectories from a directory, not files