<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Rick's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 29 Aug 2008 11:23:13 GMT</pubDate>
    <description>DZone Snippets: Rick's Code Snippets</description>
    <item>
      <title>Speeding up Java I/O - Read method</title>
      <link>http://snippets.dzone.com/posts/show/5510</link>
      <description>The following example counts the number of newline bytes ('\n') in a file. It simply uses the read method on a FileInputStream: &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; import java.io.*;&lt;br /&gt;  &lt;br /&gt;  public class intro1 {&lt;br /&gt;    public static void main(String args[]) {&lt;br /&gt;      if (args.length != 1) {&lt;br /&gt;        System.err.println("missing filename");&lt;br /&gt;        System.exit(1);&lt;br /&gt;      }&lt;br /&gt;      try {&lt;br /&gt;        FileInputStream fis =&lt;br /&gt;            new FileInputStream(args[0]);&lt;br /&gt;        int cnt = 0;&lt;br /&gt;        int b;&lt;br /&gt;        while ((b = fis.read()) != -1) {&lt;br /&gt;          if (b == '\n')&lt;br /&gt;            cnt++;&lt;br /&gt;        }&lt;br /&gt;        fis.close();&lt;br /&gt;        System.out.println(cnt);&lt;br /&gt;      }&lt;br /&gt;      catch (IOException e) {&lt;br /&gt;        System.err.println(e);&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Subject to Sun's &lt;a href="http://developers.sun.com/license/berkeley_license.html"&gt;Code Sample License&lt;/a&gt;</description>
      <pubDate>Sat, 17 May 2008 14:49:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5510</guid>
      <author>rick (Rick Ross)</author>
    </item>
  </channel>
</rss>
