【发布时间】:2014-05-05 06:39:18
【问题描述】:
您好,我想从文件中读取数据,然后我想从我的字符串中比较该字符串 我那个字符串等于我的字符串然后运行 if 条件否则 else 条件
我的.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="java.io.*" %>
<html>
<body>
<%
String s1="1";
// int i=4;
// String s=null;
// String s2="1";
String s3=null;
String file = application.getRealPath("/") + "data.txt";
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while((line = reader.readLine())!= null){
s3=line.toString();
}
if(s3.equalsIgnoreCase(s1))
%>
<%@ include file="MarketWiseData.jsp" %>
<%else
{%>
<%@ include file="CommodityWise.jsp" %>
<%
}
%>
</body>
</html>
我怎样才能得到我的目标?
提前致谢
【问题讨论】:
-
我知道如何比较,但我不知道我错在哪里
-
@san Krish 我得到了 (java.lang.NullPointerException)
-
如果你得到 NullPointerException,Reader 对象没有被创建,这意味着文件不存在。
-
即使在while循环之后,如果line变量为null,也会给出NullPointerException。
标签: java jsp bufferedreader filereader