Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

new InputStreamReader(InputStream is) Please help me understand

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;
public class Io{
public static void main(String args[]){
FileReader fr= new FileReader("c:/Io.java");
InputStreamReader = new InputStreamReader(fr);//Line 1
LineNumberInputStream = new LineNumberInputStream(fr); Line 2
}
}

BOTH InputStreamReader and LineNumberInputStream has same type of constructor which takes InputStream type.
BUT Line 1 doesnt compile
Line 2 compiles.
 
Madhu Madala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi My question is Why does Line one doesnt compile.
Thanks in Advance
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're missing variable names in line 1 and line 2. (Like 'fr' in the previous line).
Also, you're going to have a hard time doing anything useful with two different streams/readers attached to the same inner stream. The InputStreamReader and the LineNumberInputStream are both competing for bytes from the same source - each byte will be read by one of the other, but not both. Very confusing. You probably want to attach everything serially:
A a = new A();
B b = new B(a);
C c = new C(b);
D d = new D(c);
rather than
A a = new A();
B b = new B(a);
C c = new C(b);
D d = new D(a);
For your situation, this probably means using a LineNumberReader rather than a LineNumberInputStream.
 
Madhu Madala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You were right I am sorry i wanted to mention LineNumberReader lnr=new LineNumberReader(fr);
Thank you
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic