Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Parsing a String into Paragraphs Using a Regular Expression

                         

This section tells you how to parse the string into the paragraphs using regular expression in Java. In this section, you will learn about the topic through the following program. This program takes a text file from which contents of the file are read and shows the string line-by-line after waiting few some seconds. The time duration for showing string line-by-line are treated through the Thread class and time is fixed in the sleep() method of the Thread class.

 

Here is the code of the program:

 

 

import java.util.regex.*;
import java.io.*;

public class ParseStringInParagraph{
  public static void main(String[] argsthrows IOException,InterruptedException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter file name: ");
    String filename = in.readLine();
    File file = new File(filename);
    if(!filename.endsWith(".txt")){
      System.out.println("File not in text format.");
      System.exit(0);
    }
    else if(!file.exists()){
      System.out.println("File not found.");
      System.exit(0);
    }
    FileInputStream fstream = new FileInputStream(filename);
    DataInputStream ds = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(ds));
    Pattern p;
    Matcher m;
    String strLine;
    String inputText = "";
    while((strLine = br.readLine()) != nullinputText = inputText + strLine + "\n";
    String[] paras = Pattern.compile
(
"(?<=(\r\n|\r|\n))([ \\t]*$)+", Pattern.MULTILINE).split(inputText);
    Thread th = new Thread();
    for(int i=0; i<=paras.length-1; i++){
      System.out.println(paras[i]);
      th.sleep(1500);
    }
  }
}

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
.getCurrencyInstance
result tag in struts 2
toString
daouble in java
pane splitter in java
source
grafics code in java
<html:submit>
array java
sample palindrome prog
clear the console in j
struts-config.xml
how to capture multipl
Servlet Context
jsp for loop
abstract class and abs
deleterecords
present
jsf in struts
ccount()
ASP EXAMPLE and 1=1
ActionErrors in struts
java program to transp
read a file
ajax with jsp chat
sample
how 2 getAttribute for
filedownloadinstruts
hql date
change counter functio
Image with mouse drag
dispatch
Ñ?Ñ?Ñ?Ñ?Ñ?
portlet spring
usebean tag in jsp
book store application
bean header
jsp for
date function java scr
make effect on pictuer
Java Pass Value
Photoshop Textures and
AddressAction
code for transpose of
Tree Grid using flex
csv file format
a simple program of jd
xml marshling
char at
creating a file
Selection Sort In Java
transpose of a matrix
sort user input number
marshling
smartclient
interface
retrieve image from da
substring
write to text file
Flash Math Physics Fla
EXT grid
MASHLING
previous
Struts simple example
swing close button
assign flex label text
jsp MENU SELECT CREATE
Thread Sleep Method
validate radio button
j2me insert image form
sequence number genera
10 mintiues guid to an
survey js
dojo debug
length of string
activate
Convert Time to Second
Call the setLocation
Buble Sort In Java
objective c
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.