title: XML file to Json (org.json)
body: <p>I'm trying to convert XML to Json. 
  I found this example bellow and works almost like the way I wanted. But, is there any way to load the XML file from my computer and not direcly from the code? I've found some alternatives but I would like to stick with org.json if possible...</p>
  
  <p><code>public static String TEST_XML_STRING = ("C:\\results\\results.xml")</code>; or something like that?</p>
  
  <pre><code>import org.json.JSONException;
  import org.json.JSONObject;
  import org.json.XML;
  
  public class Main {
  
  
  public static int PRETTY_PRINT_INDENT_FACTOR = 4;
  public static String TEST_XML_STRING =
  
  "&lt;breakfast_menu&gt;\n"+
  "&lt;food&gt;\n"+
  "&lt;name&gt;Belgian Waffles&lt;/name&gt;\n"+
  "&lt;price&gt;$5.95&lt;/price&gt;\n"+
  "&lt;description&gt;\n"+
  "Two of our famous Belgian Waffles with plenty of real maple syrup\n"+
  "&lt;/description&gt;\n"+
  "&lt;calories&gt;650&lt;/calories&gt;\n"+
  "&lt;/food&gt;\n"+
  "&lt;food&gt;\n"+
  "&lt;name&gt;Strawberry Belgian Waffles&lt;/name&gt;\n"+
  "&lt;price&gt;$7.95&lt;/price&gt;\n"+
  "&lt;description&gt;\n"+
  "Light Belgian waffles covered with strawberries and whipped cream\n"+
  "&lt;/description&gt;\n"+
  "&lt;calories&gt;900&lt;/calories&gt;\n"+
  "&lt;/food&gt;\n"+
  "&lt;/breakfast_menu&gt;";
  
  
  public static void main(String[] args) {
  try {JSONObject xmlJSONObj = XML.toJSONObject(TEST_XML_STRING);
  
  String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
  System.out.println(jsonPrettyPrintString);
  
  } catch (JSONException e) {
      System.out.println(e.toString());
  }
  
  
  }
  }
  </code></pre>
  
  <p>I've got into this, but gives me error on line 20</p>
  
  <p>Exception in thread "main" java.lang.Error: Unresolved compilation problem: at Main.main(Main.java:20)</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  
  import org.json.JSONException;
  import org.json.JSONObject;
  import org.json.XML;
  
  public class Main {
  
      File file = new File("teste.xml");
      FileInputStream fin = new FileInputStream(file);
      byte[] xmlData = new byte[(int) file.length()];
      fin.read(xmlData);
      fin.close();
  
  public static int PRETTY_PRINT_INDENT_FACTOR = 4;
  public static String TEST_XML_STRING = new String(xmlData, "UTF-8");
  
  
  public static void main(String[] args) {
  try {JSONObject xmlJSONObj = XML.toJSONObject(TEST_XML_STRING);
  
  String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
  System.out.println(jsonPrettyPrintString);
  
  } catch (JSONException e) {
      System.out.println(e.toString());
  }
  
  
  }
  }
  </code></pre>