my dog learned polymorphism*
The moose likes I/O and Streams and the fly likes Help with BufferedReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Help with BufferedReader" Watch "Help with BufferedReader" New topic
Author

Help with BufferedReader

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi.
How can i identify the given input is null. Here i have a small code. But if i doesn't enter any value also it shows as valid. Heres the code


Somebody please help me out of this.

Thanks & Regards
alexander
Rishita Pallavi
Greenhorn

Joined: Jun 27, 2009
Posts: 7
Change if(input=="") to if(input.equals(""))
It will work.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42911
    
  68
Keep in mind that readLine can return null, so before calling input.equals you need to check for input being null.
Rishita Pallavi
Greenhorn

Joined: Jun 27, 2009
Posts: 7
In what cases can it return null? Im testing this from my eclipse IDE and not able to simulate a case when it can return a null so that it can fail.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42911
    
  68
From the javadocs:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached.
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi,
thanks for replying, i am unable to solve the problem as pallavi said i have used input.equals("") but this is not the only one condition in which it needs to work. If the user gives the input as a space or a tab or 2 or mare spaces or 2 or more tabs it does'nt work. I have also used the trim() method i.e input.trim() also insane. Some body please help me out

heres the code


Thanks and Regards
alexander
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

How about Remember, Strings are immutable.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
sandip sangale
Greenhorn

Joined: Jun 22, 2009
Posts: 15
As i understood your problem
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Thanks a lot prime what you said really worked thanks again. I have one more question i will start it as new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with BufferedReader