The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
March 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

"readLine" is not working

Posted by Bhargav on December 26, 2001 at 6:57 AM

i have tried out readLine() but then the record which i am reading from a text file is very large for the string variable which i am using , hence it is reading but then at the end giving exception. pls help...
my code is like this... :-

/*****code goes here****/

f = new File("test.txt");

FileReader fr = new FileReader(f);

BufferedReader br = new BufferedReader(fr);

String rec;

while((rec = br.readLine()) != null)
{
//some code..
}

psl help it is urgent...
thank u..

bhargav..
> > I want to know if it is possible to read a whole file once into
> > a string or into a char array ( not byte[] ).
> > If it isn't possible , since I know how to read the file once into
> > a byte array, so is there anyway to convert a byte array to a char
> > array ?

> Yes. I've done this before. Create a StringBuffer to hold your data and a BufferedReader to read it in. Then, write a loop that uses readLine() to read in each line of data and append it to what you've already read.






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us