aspose file tools*
The moose likes JavaFX and the fly likes how to detect a paragraph when reading text file in java. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "how to detect a paragraph when reading text file in java." Watch "how to detect a paragraph when reading text file in java." New topic
Author

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

Clarence Lim
Greenhorn

Joined: Nov 05, 2009
Posts: 1
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

Joined: Jun 06, 2002
Posts: 181
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.


love your job and not your company;
...because you never know when your company will stop loving you!
Philippe Lhoste
Greenhorn

Joined: Oct 23, 2009
Posts: 28
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to detect a paragraph when reading text file in java.