<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: text file input stream code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 12 Oct 2008 10:47:35 GMT</pubDate>
    <description>DZone Snippets: text file input stream code</description>
    <item>
      <title>Loading a text file into a String from the classpath</title>
      <link>http://snippets.dzone.com/posts/show/4480</link>
      <description>Locate a text file in the classpath and read it into a String&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    /** &lt;br /&gt;     * @param filePath      name of file to open. The file can reside&lt;br /&gt;     *                      anywhere in the classpath&lt;br /&gt;     */&lt;br /&gt;    private String readFileAsString(String filePath) throws java.io.IOException {&lt;br /&gt;        StringBuffer fileData = new StringBuffer(1000);&lt;br /&gt;        BufferedReader reader = new BufferedReader(new InputStreamReader(this&lt;br /&gt;            .getClass().getClassLoader().getResourceAsStream(filePath)));&lt;br /&gt;        char[] buf = new char[1024];&lt;br /&gt;        int numRead = 0;&lt;br /&gt;        while ((numRead = reader.read(buf)) != -1) {&lt;br /&gt;            String readData = String.valueOf(buf, 0, numRead);&lt;br /&gt;            fileData.append(readData);&lt;br /&gt;            buf = new char[1024];&lt;br /&gt;        }&lt;br /&gt;        reader.close();&lt;br /&gt;        return fileData.toString();&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 30 Aug 2007 12:48:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4480</guid>
      <author>Archanciel ()</author>
    </item>
  </channel>
</rss>
