[英]java String != null not working reading from bufferedReader
In android I am getting the String value from BufferedReader and it is null after reading from file. 在android中,我从BufferedReader获取String值,并且从文件读取后为null。
intstring = br.readLine();
System.out.println(intstring);
if(intstring != null)
{
System.out.println("Inside if condition");
int istring = Integer.parseInt(intstring);
}
My output is 我的输出是
null
Inside if condition
NumberFormatException
Help me please 请帮帮我
Your NumberFormatException
is happening because your input isn't a number. 您的
NumberFormatException
发生了,因为您输入的不是数字。 Maybe it's a blank line, or maybe it has some non-numeric characters. 可能是空白行,或者可能包含一些非数字字符。 In fact, your output suggests that it's actually the word
"null"
. 实际上,您的输出表明它实际上是单词
"null"
。
You've got some options. 您有一些选择。
if (intString.matches("\\\\d+"))
. if (intString.matches("\\\\d+"))
。 NumberFormatException
, and do something particular when it happens. NumberFormatException
,并在发生这种情况时做一些特别的事情。 if (!intString.equals("")))
. if (!intString.equals("")))
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.