I have tried really hard to solve this with previous similar answers, but am still nto able to see my problem, hope you can help. My code looks like this:
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(); And I am getting an error:
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") 13 Answers
First, the method readLine() in DataInputStream is deprecated.
Second, this method returns a String, which doesn't have a field length. It only has the method length(). length is a property of arrays.
length is not an field. It is a function, so you have to call nextline.length() > 4
length is not a property, it is a method..
Use
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; } } }