Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to detect a paragraph when reading text file in java.

 
Clarence Lim
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, I would like to read a text file, and write a new text file with the exact content of the input file. However, I am unable to reproduce the exact same file as the input text. In the input text file, there are paragraphs in between blocks of words. How can I write the new file in exactly the same way, with the paragraphs in between? I am able to produce the whole chunk of text with stringtokenizer, by counting the number of words per line, set a restriction, and when the limit is reach, go on to the new line, but while((input = br.readLine()) != null) doesn't seems to work for paragraph, how to make sure that the program can detect a paragraph, so that I am able to write a new line when a paragraph is being detected?

e.g. of input text :
Oxford Circus, the heart of London's West End shopping and entertainment district, got a Tokyo-style makeover Monday with a new "scramble crossing" layout.

London Mayor Boris Johnson launched the new scheme, aimed at cutting crowd congestion and the lengthy traipse round the interchange. People are now able to walk diagonally across to their destination in a pedestrian free-for-all.

desire output: exactly the same as above, with paragraph

what I got (without the paragraph):

Oxford Circus, the heart of London's West End shopping and entertainment district, got a Tokyo-style makeover Monday with a new "scramble crossing" layout.
London Mayor Boris Johnson launched the new scheme, aimed at cutting crowd congestion and the lengthy traipse round the interchange. People are now able to walk diagonally across to their destination in a pedestrian free-for-all.


Thanks, any guidance on the logic to solve the problem is appreciated.
 
manoj r patil
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I understood from your post is you want to replicate the same file. In that case why are you reading it line by line? better read it character by character till you get '-1' and write it to your new file.
 
Philippe Lhoste
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clarence, for the record, you are in a JavaFX forum, not in a Java one.

Beside, you should give a more precise specification of your needs.
If I understood correctly, you actually want to reformat your text with hard-wrapping at word boundary at a given char (line width) limit. Right?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic