0

Reading first json with this name TestNameUS.json from the amazon S3Client directory and getting the sql from it and then hitting the db using the sql and matching the result with other Amazon S3 output directory containing the TestNameUS.csv with the same name as the name of the first json. My code is below. It gives me the sql.How to read the directory dynamically with the name

public class ReadJsonFile {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        JSONParser jsonParser = new JSONParser();
        try {
            Object obj = jsonParser.parse(new FileReader("./TestNameUS.json"));

            // A JSON object. Key value pairs are unordered. JSONObject supports java.util.Map interface.
            JSONObject jsonObject = (JSONObject) obj;

            JSONArray query = (JSONArray) jsonObject.get("query");
            String query1=null;
            for(Object str : query) {
               query1=(String)str;
            }
            System.out.println(query1);
            System.out.println(query1.replaceAll("^\\('|\\'\\)$", ""));

        } catch (Exception e) {
          e.printStackTrace();
        }

    }

}
Ashu
  • 1
  • 3
  • Which s3 are you using? – MOnkey Feb 23 '20 at 06:11
  • amazon s3 bucket – Ashu Feb 23 '20 at 06:52
  • Have you check this link https://stackoverflow.com/questions/28568635/read-aws-s3-file-to-java-code – MOnkey Feb 23 '20 at 06:53
  • It's taking the file with the filename.I need to have it dynamically like Navigate to S3 folder take the file in list get the first file as TestFilleUS.json and similarly take from another S3 folder the csv file with the same name so this will happen for other file which have the name TestFileEU.json and then will navigate to another S3 folder take the file with the name TestFileEU.csv. This will continue for 30 json and csv files. – Ashu Feb 23 '20 at 06:58

0 Answers0