title: How to convert xml to .json file in java
body: <pre><code>  public class ConvertXMLtoJSON {
  
      public static void main(String[] args) throws Exception {
          InputStream in =             ConvertXMLtoJSON.class.getResourceAsStream("D:\\sample.xml");
          String xml = IOUtils.toString(in);
          XMLSerializer xmlSerializer = new XMLSerializer(); 
          JSON json = xmlSerializer.read(xml);  
          System.out.println(json.toString(2));
      }
        }
  </code></pre>
  
  <p>but i am getting error</p>
  
  <pre><code>      Exception in thread "main" java.lang.NullPointerException
  at java.io.Reader.&lt;init&gt;(Reader.java:78)
  at java.io.InputStreamReader.&lt;init&gt;(InputStreamReader.java:72)
  at org.apache.commons.io.IOUtils.copy(IOUtils.java:1020)
  at org.apache.commons.io.IOUtils.toString(IOUtils.java:358)
  at com.apache.poi.ConvertXMLtoJSON.main(ConvertXMLtoJSON.java:13
  </code></pre>
  
  <p>can u please help me to resolve it
  This is my xml format
               
         
          ac3
          AC3 Phone
          ACME
          phone
          200.0 
          1.0 
          true
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
      
           </p>
  
  <p>i have generated this xml from my excel file and i have convert this xml file to json file </p>