[英].length cannot be resolved or is not a field
我已經盡力用以前的類似答案來解決這個問題,但是仍然無法看到我的問題,希望能對您有所幫助。 我的代碼如下所示:
String MyContent =" ";
String nextline = " ";
InputStream in = new FileInputStream(f);
BufferedInputStream bin = new BufferedInputStream(in);
DataInputStream din = new DataInputStream(bin);
while(din.available()>1)
{
nextline = din.readLine();
//Filter out XML headers which are not browser compliant
if (nextline.length > 4)
{
if (nextline.substring(1,5) != "<?xml")
{
MyContent=MyContent+ nextline;
}
}
}
out.print (MyContent);
in.close();
bin.close();
din.close();
我收到一個錯誤:
An error occurred at line: 25 in the jsp file: /MaxiSunReports/DisplayXMLFile.jsp
nextline.length cannot be resolved or is not a field
22: nextline = din.readLine();
23: nextline = "THISISATEST";
24: //Filter out XML headers which are not browser compliant
25: if (nextline.length > 4)
26: {
27: if (nextline.substring(1,5) != "<?xml")
首先,不贊成使用DataInputStream
readLine()
方法。
其次,此方法返回一個String
,它沒有field
length
。 它只有方法length()
。 length
是數組的屬性。
length
不是字段。 這是一個函數,因此您必須調用nextline.length() > 4
長度不是屬性,而是方法。
采用
while(din.available()>1)
{
nextline = din.readLine();
//Filter out XML headers which are not browser compliant
if (nextline.length() > 4)
{
if (nextline.substring(1,5) != "<?xml")
{
MyContent=MyContent+ nextline;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.