Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

use NIO FileChannel Question

evebill8Mar 6 2009 — edited Mar 10 2009
Hi folks,

I have a process that needs to read lots of large UTF-8 files. I am finding a way to speed up the read process. I use the traditional way to read because the BufferedReader provides me the readLine() function so I do not need to parse the carriage return.

BufferedReader  in = new BufferedReader(new InputStreamReader(new FileInputStream(file), BzFileUtil.UTF8));
String line;
while ((line = in.readLine()) != null) { 
    ......
}    
in.close();
If I want to use Channel, I will lose the readLine(). I found I can create the BufferedReader with Channel, so iI test it. Howerver, I do not notice it makes any faster.
ReadableByteChannel in = new FileInputStream(file).getChannel();

BufferedReader reader=new BufferedReader(Channels.newReader(in, "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
     ....
}
reader.close();
Would anyone tell me how I could use the Channel to read lines in the UTF-8 files? Any input will helps, thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 7 2009
Added on Mar 6 2009
14 comments
577 views