title: Read file As String
body: <p>I need to load an xml file as String in android so I can load it to TBXML xml parser library and parse it. The implementation I have now to read the file as String takes around 2seconds even for a very small xml file of some KBs. Is there any known fast method that can read a file as string in Java/Android?</p>
  
  <hr>
  
  <p>This is the code I have now:</p>
  
  <pre><code>public static String readFileAsString(String filePath) {
      String result = "";
      File file = new File(filePath);
      if ( file.exists() ) {
          //byte[] buffer = new byte[(int) new File(filePath).length()];
          FileInputStream fis = null;
          try {
              //f = new BufferedInputStream(new FileInputStream(filePath));
              //f.read(buffer);
  
              fis = new FileInputStream(file);
              char current;
              while (fis.available() &gt; 0) {
                  current = (char) fis.read();
                  result = result + String.valueOf(current);
              }
          } catch (Exception e) {
              Log.d("TourGuide", e.toString());
          } finally {
              if (fis != null)
                  try {
                      fis.close();
                  } catch (IOException ignored) {
              }
          }
          //result = new String(buffer);
      }
      return result;
  }
  </code></pre>