title: Automatically read JSON from the path
body: <p>I am using the following code to read JSON from the project folder and then execute kafka producer code.</p>
  
  <p>Right now, it is in <code>while loop</code> so code execution is happening continuously. </p>
  
  <p>If I want to replace a new "test.json" in the same path. Expecting this time, automatically the code should read the new "test.json" that is being updated in the same project folder. How to get this code automatically read if there is any new "test.json" being updated in the same path? </p>
  
  <p>The existing below code is not reading if I copy/paste a new "test.json" in the path.</p>
  
  <pre><code>public void doPost(HttpServletRequest request, HttpServletResponse response)
  throws IOException, ServletException {
  
      while (true) {           
          try {           
              URL url = getClass().getResource("test.json");
              File file = new File(url.getPath());
              Properties props = new Properties();            
              props.put("bootstrap.servers", "yupsectory.selet.com:9092");
              props.put("client.id", CLIENT_ID);
              props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
              props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
              String jsonData = readFile(file.getAbsolutePath());
              JSONObject jobj = new JSONObject(jsonData);    
              System.out.println("jarr: " + jobj.getJSONObject("data").toString());    
              Yupsectoryproducer&lt;String, String&gt; producer = new Yupsectoryproducer &lt;&gt;(props);      
              //Use this util to pull the context that needs to be propagated from the HttpServletRequest
              Map&lt;String, String&gt; headermap = YupsectoryContextUtil.buildContextMap(request);
              //Sending a message
              ProducerRecord&lt;String, String&gt; record = new ProducerRecord&lt;String, String&gt;(topic, jobj.getJSONObject("data").toString());
              producer.send(record, headermap);           
              producer.close();                 
          } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>