The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 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:

okay

Posted by Chin Loong on October 28, 2001 at 11:50 PM

this is what i use to read from a file. all the characters read will be put into an array (which is ch[]). i have an appointment with this girl in 15 mins and i risk getting late for it. u owe me one man :p

just kidding ;)


File f=new File("yourfilename.txt");
if (f.exists())
{
String data=new String("");
InputStream in=new FileInputStream(f);
int b,count=0;
char[] ch=new char[255];
while (true)
{
b = in.read();
if (b == 10 || b == -1 || count == 255)
{
data=data.concat(new String(ch,0,count));
if (count!=255)
data=data.concat("\n");
count=0;
if(b == -1)
break;
}
else
{
ch[count]=(char)b;
count++;
}
}
in.close();
}




Replies:

Sponsored Links



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