aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes input reading problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "input reading problem" Watch "input reading problem" New topic
Author

input reading problem

Jason sigel
Ranch Hand

Joined: Oct 07, 2003
Posts: 30

D:\mycode>javac my1.java
my1.java:10: Method readDouble() not found in class java.io.BufferedReader.
double d=br.readDouble();
^
1 error

I am getting this error .I have again write out a simple program in this form.

Now tell me why i can not use br.readDouble()
jaideep
[I added UBB CODE tags to your source code to make it more readable. Please try to use
them in the future. Learn more about UBB codes here - Ajith ]

[This message has been edited by Ajith Kallambella (edited September 27, 2000).]
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Did you read the error message?

D:\mycode>javac my1.java
my1.java:10: Method readDouble() not found in class java.io.BufferedReader. double d=br.readDouble();

That's why.
BufferedReader only gives you the advantage of buffering your reads from the stream. It does a 'read-ahead' from the stream so when you read, you are actually reading from the buffer which is faster than reading from the stream itself. Eventhough it wraps an input stream, it doesnot deal with any of the methods associated with the underlying inputstream object. So, if you have to use BufferedReader, you should live with the high-level methods it provides for reading. Ofcourse, you can always use other ways to convert the String that was read.
Hope that helps,
Ajith

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Marie
Greenhorn

Joined: Oct 10, 2002
Posts: 4
Readers and Writers only work with Unicode... don't they?
to read primitives, you need to use RandomAccessFile or one of the InputStreams
i think....


Marie
Jason sigel
Ranch Hand

Joined: Oct 07, 2003
Posts: 30
tHANKS AJITH,
I got where I had made mistake.Yes UBB code make effective way to present code.
Marie you are right.This is what I am doing here.I am taking input stream and passing it to buffered reader.
InputStream converts bytes to char and buffered reader is character reader.
jaideep
Jason sigel
Ranch Hand

Joined: Oct 07, 2003
Posts: 30
One more question related elementry thing here.
why I have to initialize d=0.00 here in the code .

WHY NOT JUST double d=Double.parseDouble(br.readLine());}
jaideep

[This message has been edited by Ajith Kallambella (edited September 27, 2000).]
Henry H
Greenhorn

Joined: Sep 22, 2000
Posts: 5

WHY NOT JUST double d=Double.parseDouble(br.readLine());}
jaideep[/b]
</BLOCKQUOTE>
That would actually fail to compile since you're declaring 'd' twice in the method. Marked 1) and 2) in the code.
Change 1) to: double d = 0.0;" and
2) to d=Double.parseDouble(br.readLine());
You need to initialize d before you go into any code block(ie try/catch, loops)

[This message has been edited by Henry H (edited September 27, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: input reading problem