The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2002

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:

Some questions...

Posted by Hiran on January 17, 2002 at 1:50 PM

Chin, thanks for the code, but I have a few clarification questions. First, I don't quite understand the

new String(ch,0,count) part
. Did you do that slightly wrong? Secondly, why is the char array set to 255? Thirdly (kinda tied into the second question), why are you concatenating when b = 10, -1, or 255? What's so special about them? Thanks again though Chin.
Hiran

>


> serviceHistory=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)
> {
> serviceHistory=serviceHistory.concat(new String(ch,0,count));
> if (count!=255)
> serviceHistory=serviceHistory.concat("\n");
> count=0;
> if(b == -1)
> break;
> }
> else
> {
> ch[count]=(char)b;
> count++;
> }
> }
> in.close();
>

> mr. lecturer, please grade :p






Replies:
  • explanation Chin Loong January 18, 2002 at 4:42 AM (0)

Sponsored Links



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