• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read text from a text file using jsp

 
ash neet
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

I have a menu item, when I click the menu item, i want to display text from a 'text' file into the html page. i can display the text. but the problem is, it doesnt read paragraphs. for e.g, if the following text is present in the text file -

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam nibh. Nunc varius facilisis eros. Sed erat. In in velit quis arcu ornare laoreet. Curabitur adipiscing luctus massa. Integer ut purus ac augue commodo commodo. Nunc nec mi eu justo tempor consectetuer. Maecenas facilisis elit sed justo. Quisque volutpat malesuada velit.

Nunc at velit quis lectus nonummy eleifend. Curabitur eros. Aenean ligula dolor, gravida auctor, auctor et, suscipit in, erat. Sed malesuada, enim ut congue pharetra, massa elit convallis pede, ornare scelerisque libero neque ut neque.

-Then only the first paragraph is displayed.

I have used the following code-

File inputfile = new File(path);

BufferedReader br = new BufferedReader(new FileReader(inputfile));

String str = br.readLine();

<%=str%>

regards,

Ash Neet
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only read and display the first line. You should loop through all lines by calling readLine() until it returns null.
 
ash neet
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:You only read and display the first line. You should loop through all lines by calling readLine() until it returns null.


okay I got it. i used while loop. but i want the same format that is in the text file. i.e, indentation at paragraphs.
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you have to introduce HTML markup as you read the file (i.e. add a "<p>" when you hit a blank line)
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<p> doesn't maintain indentation. <pre> does but it also changes the font to a mono spaced one (usually Courier New).
 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, I was thinking vertical space, not horizontal space
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!