java - Facing: The method readLine() is undefined for the type String -
i have java program named p_builder.java.
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.lang.*; import java.text.*; import java.util.*; public class p_builder { public string pb_reader( string file_location, string pb_cmd)throws ioexception { file file=new file(file_location); processbuilder pb = new processbuilder("cmd","/c",pb_cmd); pb.directory(file); process p = pb.start(); bufferedreader reader = new bufferedreader(new inputstreamreader( p.getinputstream())); string readline= reader.tostring(); return readline; /*string readline=null; do{ return readline; }while((readline = reader.readline()) != null);*/ } }
now using p_builder.java in a.jsp multiples times since need run process builder multiple times.
i want line wise output of p_builder sent a.jsp can read line wise output using readline() method , print output using a.jsp have omit few lines in output.
a.jsp
<%@ page import="java.io.*"%> <%@ page import="javax.servlet.*"%> <%@ page import="javax.servlet.http.*"%> <%@ page import="java.text.decimalformat"%> <%@ page import="license_dashboard.p_builder" %> string pcm= "lmutil.exe lmstat -a -c 426@stiosp569"; p_builder p1=new p_builder(); string readline1=p1.pb_reader("d:\\singula\\log", pcm); string readline; int j=0; while ((readline = readline1.readline()) != null) { if(j==2 || j==3 || j==6) { //out.println(readline); //out.println("<br>"); } else if(j>9) { out.println(readline); out.println("<br>"); } else { //out.println("<br>"); } j++; }
after facing error:- "the method readline() undefined type string" in a.jspin while loop.
update:- 5:23pm
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.lang.*; import java.text.*; import java.util.*; public class p_builder { public string pb_reader( string file_location, string pb_cmd)throws ioexception { file file=new file(file_location); processbuilder pb = new processbuilder("cmd","/c",pb_cmd); pb.directory(file); process p = pb.start(); bufferedreader reader = new bufferedreader(new inputstreamreader( p.getinputstream())); return reader; //string readline= reader.tostring(); //return readline; /*string readline=null; do{ return readline; }while((readline = reader.readline()) != null);*/ } }
even gives error since needs return string type. how can make return type bufferedreader since want return multiple values read bufferedreader.
after can tell how can catch values in jsp , print them on webpage.
update:- 7:00pm
public class p_builder { public string pb_reader( string file_location, string pb_cmd)throws ioexception { file file=new file(file_location); processbuilder pb = new processbuilder("cmd","/c",pb_cmd); pb.directory(file); process p = pb.start(); bufferedreader reader = new bufferedreader(new inputstreamreader( p.getinputstream())); stringbuffer result=new stringbuffer(); string readline; while((readline = reader.readline()) != null) { //this.fin_readline[j]=readline+"\n"; result.append(readline); result.append("\n"); } } return result.tostring(); }
now a.jsp has been modififed:-
<% out.println("\n"); try{ p_builder p1=new test_p_builder(); string pcm= "lmutil.exe lmstat -a -c 426@stiosp569"; string res=p1.b_reader("d:\\singula\\log", pcm); string[] lines = res.tostring().split("\\n"); int j=0; for(string readline:lines) { if(j>3) { out.println(readline); } j++; } } catch(exception e) { out.println(e); }
%>
now output not coming aligned. screen print attached.
would appreciate resolution output aligned?
output after giving out.println(readline + "
"); in jsp
your pb_reader
method needs return bufferedreader
not string
.
string readline= reader.tostring();
reason decide string representation of reader. don't that.
Comments
Post a Comment