0

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

Magic
  • 505
  • 2
  • 6
  • 19
  • 1
    I suggest to read https://docs.oracle.com/javase/tutorial/essential/io/find.html, there is also a nice example there.. – Jonnathan Q Mar 16 '18 at 19:40

1 Answers1

0

I used this Java, List only subdirectories from a directory, not files to get all the directories and found the one that started with 'dos-'. Thanks

Magic
  • 505
  • 2
  • 6
  • 19