dcsimg
Reading a file line-by-line using NIO
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Narasimhan_Chakravarthy
Posted On:   Tuesday, April 20, 2004 11:56 PM

How do I read from a file one line at a time using nio?
I have already used BufferedReader of th io package

Re: Reading a file line-by-line using NIO

Posted By:   gaurav_saini  
Posted On:   Thursday, April 22, 2004 03:55 AM

Test1.Java


import java.io.*;
class Test1
{
public static void main(String[] args)
{
BufferedReader in=null;
String line=null;
try{
in = new BufferedReader(new InputStreamReader(new FileInputStream("Demo.txt")));
}catch (IOException e) {}
try{
while ((line = in.readLine()) != null)
System.out.println(line);
}catch (IOException e) {}
}
}


Demo.txt

Hello How r u?

I am fine thank u!

Come compile the code

It works!

About | Sitemap | Contact