Professional Documents
Culture Documents
HowtoreadfilecontentintextareainJSP?StackOverflow
signup
login
tour
help
Dismiss
AnnouncingStackOverflowDocumentation
WestartedwithQ&A.Technicaldocumentationisnext,andweneedyourhelp.
Whetheryou'reabeginneroranexperienceddeveloper,youcancontribute.
Signupandstarthelping
LearnmoreaboutDocumentation
HowtoreadfilecontentintextareainJSP?
Inbelowcode,IamtryingtoreadthefilecontentinthetextareainJSPit'sdisplayingcontentbutforeachlineit'screatingnewtextareas.Ineed
toprintthewholecontentinonetextarea.Hereisthecode
<%@pageimport="java.io.BufferedReader"%>
<%@pageimport="java.io.FileReader"%>
<%@pageimport="java.io.IOException"%>
<%
BufferedReaderbr=null;
try{
StringsCurrentLine;
br=newBufferedReader(new
FileReader("C:\\Users\\windows\\Documents\\NetBeansProjects\\Pricing\\build\\web\\image\\"
+s+""));
while((sCurrentLine=br.readLine())!=null){
System.out.println(sCurrentLine);
%>
<textarearows="10"cols="25"><%=sCurrentLine%></textarea>
<%
}
}catch(IOExceptione){
e.printStackTrace();
}finally{
try{
if(br!=null){
br.close();
}
}catch(IOExceptionex){
ex.printStackTrace();
}
}
%>
file jsp textarea
editedSep11'14at17:18
askedSep11'14at15:39
Tiny
5,127
user2503585
52
187
340
36
2Answers
<%@pageimport="java.io.BufferedReader"%>
<%@pageimport="java.io.FileReader"%>
<%@pageimport="java.io.IOException"%>
<%
BufferedReaderbr=null;
StringmyString="";
try{
StringsCurrentLine;
http://stackoverflow.com/questions/25791708/howtoreadfilecontentintextareainjsp
1/2
20/09/2016
HowtoreadfilecontentintextareainJSP?StackOverflow
br=newBufferedReader(new
FileReader("C:\\Users\\windows\\Documents\\NetBeansProjects\\Pricing\\build\\web\\image\\"+s
while((sCurrentLine=br.readLine())!=null){
System.out.println(sCurrentLine);
myString+=sCurrentLine;
}
%>
<textarearows="10"cols="25"><%=myString%></textarea>
<%
}catch(IOExceptione){
e.printStackTrace();
}finally{
try{
if(br!=null)br.close();
}catch(IOExceptionex){
ex.printStackTrace();
}
}
%>
answeredSep11'14at17:13
brso05
10.4k
27
Your'textarea'mustbeoutsidethewhileloop.Thenyoumustappendresulttoprevious
sCurrentLine.Somethinglikethis:
while((sCurrentLine+=br.readLine())!=null){
answeredSep11'14at15:46
GrgoryVorbe
289
http://stackoverflow.com/questions/25791708/howtoreadfilecontentintextareainjsp
2/2