<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Java Code Samples</title>
	<atom:link href="http://webbyjava.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://webbyjava.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sat, 06 Dec 2008 09:17:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='webbyjava.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Java Code Samples</title>
		<link>http://webbyjava.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://webbyjava.wordpress.com/osd.xml" title="Java Code Samples" />
	<atom:link rel='hub' href='http://webbyjava.wordpress.com/?pushpress=hub'/>
		<item>
		<title></title>
		<link>http://webbyjava.wordpress.com/2008/12/06/rico-live-grid/</link>
		<comments>http://webbyjava.wordpress.com/2008/12/06/rico-live-grid/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 08:22:38 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Rico Live Grid]]></category>
		<category><![CDATA[ajax grid]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[grid with sorting]]></category>
		<category><![CDATA[java grid]]></category>
		<category><![CDATA[live grid]]></category>
		<category><![CDATA[rico sorting grid]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=50</guid>
		<description><![CDATA[Rico Live Grid Application with Java Plug in Here we are discussing the Rico Live and Super grid implementation with java plug in. Rico provides a very simple interface for registering Ajax request handlers as well as HTML elements or JavaScript objects as Ajax response objects .This Implementation only supports MySQL and Oracle database. Java [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=50&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Rico Live Grid Application with Java Plug in</strong></p>
<p>Here we are discussing the Rico Live and Super grid implementation with java plug in. Rico provides a very simple interface for registering Ajax request handlers as well as HTML elements or JavaScript objects as Ajax response objects .This Implementation only supports MySQL and Oracle database. Java Implementation only supports live grid scrolling, sorting, search row, hide/show features. Will be updating filters soon.</p>
<p>Here are the steps for Rico live grid with Java Web Application.</p>
<p>Downloads:</p>
<pre>    • Download Jar files:

        1. dom4j-1.5.2.jar
           Download Link : <a href="http://www.dom4j.org/"> Dom4j</a>
        2.mysql-connector-java-3.1.10-bin.jar
           Download Link : <a href="http://www.mysql.com/products/connector/j/">MySQLConnector</a>
        3.ojdbc14.jar
           Download Link : <a href="http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc9201.html">Oracle Connector</a>

     •	Download Rico live grid

        1.Rico Live grid
           Download Link : <a href="http://sourceforge.net/projects/openrico/">Rico Live Grid</a>

           Unzip the file and copy all files and folders from  src  folder and  paste to WebContent/js/rico

     •	Download rico supergrid items:

        1.Rico Super Grid
           Download Link : <a href="http://www.esnips.com/web/ricodemo">Rico Super Grid</a>

          Unzip the file and copy ,
          1.	ricoSuperGrid.js and paste to WebContent/js/rico
          2.	table.css and 1x1.gif and paste  to WebContent/ GridShow-Dateien
          3.	main.css and ie5-7.css and paste to WebContent/css
        Download Rico Live grid along with super grid and paste it in the appropriate folders.Please Refer previous one., ie, Download Rico live grid
</pre>
<p>Please refer the directory structure,</p>
<p>Directory Structure :<br />
•	Simple Structure</p>
<p><img class="alignnone size-full wp-image-59" title="webcontent2" src="http://webbyjava.files.wordpress.com/2008/12/webcontent2.gif?w=185&#038;h=207" alt="webcontent2" width="185" height="207" /><br />
•	Detailed Structure</p>
<p><img class="alignnone size-full wp-image-60" title="webcontent-rico-files-open" src="http://webbyjava.files.wordpress.com/2008/12/webcontent-rico-files-open.gif?w=295&#038;h=744" alt="webcontent-rico-files-open" width="295" height="744" /></p>
<p>1. Servlet Implementation :</p>
<p>You have to call this from the Rico Live Grid as “/ricoXMLquery”</p>
<pre>package com.ricogrid.servlets;

import java.io.IOException;
import java.sql.Connection;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ricogrid.Utils.DBConnection;
import com.ricogrid.Utils.MySQLQueryGenerator;
import com.ricogrid.Utils.OracleQueryGenerator;

public class RicoXMLQuery extends HttpServlet {

	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		DBConnection dbConnection = null;
		Connection connection = null;

		System.out.println("Processing rico sql request");

		try {
			int limit = 20;
			String responseString = "";

			String id = (request.getParameter("id") != null) ? request
					.getParameter("id") : "";

			limit = (request.getParameter("limit") != null) ? Integer
					.parseInt(request.getParameter("limit")) : limit;

			int offset = (request.getParameter("offset") != null) ? Integer
					.parseInt(request.getParameter("offset")) : 0;

			/*
			 * String size = (request.getParameter("page_size") != null) ?
			 * request.getParameter("page_size") : "";
			 *
			 * boolean total = (request.getParameter("get_total") != null) ?
			 * Boolean.getBoolean(request.getParameter("get_total").toString()):
			 * false;
			 *
			 * String distinct = (request.getParameter("distinct") != null) ?
			 * request.getParameter("distinct"): "";
			 */

			String sqlQuery = (String) request.getSession().getAttribute(id);

			dbConnection = new DBConnection(getServletContext().getRealPath("/WEB-INF/db.properties"));
			connection =  dbConnection.getConnection();
			String dialect  = dbConnection.getDialect();
			Map paramMap = request.getParameterMap();

			if( "MySQL".equals( dialect )){
				//if MySQL
				responseString = MySQLQueryGenerator.generateRicoResponseXML( connection, sqlQuery, paramMap,
                                                       offset, limit, dialect );
			}else{
				//if Oracle
				responseString = OracleQueryGenerator.generateRicoResponseXML( connection, sqlQuery, paramMap,
                                                       offset, limit, dialect );
			}
			response.setHeader("Content-Type", "text/xml");
			ServletOutputStream sos = response.getOutputStream();
			sos.write(responseString.getBytes());
			System.out.println("Processing rico sql request - Complete");

		} catch (Exception e) {

			e.printStackTrace();
		} finally {
			dbConnection.closeConnection(connection);
		}
	}

}</pre>
<p>2:  Database Connection class:</p>
<p>This Class is used for database Connectivity, getConnection Method gives you the Connection Object</p>
<pre>package com.ricogrid.Utils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBConnection {
	Connection connection;
	Properties propertyObj;
	String sql_driver;
	String sql_url_database;
	String sql_user;
	String sql_password;
	public String dialect;
	public DBConnection(String location) {
		try {
			propertyObj = new Properties();
			propertyObj.load(new FileInputStream(location));
			dialect = propertyObj.get("dialect").toString();
			this.setDialect( dialect );
			// MySQL Connection parameters
			if ("MySQL".equals(dialect.trim())) {
				sql_driver = propertyObj.get("sql.driver").toString();
				sql_url_database = propertyObj.get("sql.url.datasource").toString();
				sql_user = propertyObj.get("sql.user").toString();
				sql_password = propertyObj.get("sql.password").toString();
			}
			// Oracle Connection Parameters
			if ("Oracle".equals(dialect.trim())) {
				sql_driver = propertyObj.get("oracle.driver").toString();
				sql_url_database = propertyObj.get("oracle.url.datasource").toString();
				sql_user = propertyObj.get("oracle.user").toString();
				sql_password = propertyObj.get("oracle.password").toString();
			}

			Class.forName(sql_driver);
			connection = DriverManager.getConnection(sql_url_database,sql_user, sql_password);

			this.setConnection(connection);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * returns connection Object
	 *
	 * @return Connection
	 */
	public Connection getConnection() {
		return connection;
	}

	/**
	 * set the connection object
	 *
	 * @param connection
	 *            the connection to set
	 */
	public void setConnection(Connection connection) {
		this.connection = connection;
	}

	/**
	 * Method is used to close the connection Object
	 *
	 * @param con
	 *            -- indicates connection Object
	 */
	public void closeConnection(Connection con) {

		try {
			con.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * @return the dialect
	 */
	public String getDialect() {
		return dialect;
	}

	/**
	 * @param dialect the dialect to set
	 */
	public void setDialect(String dialect) {
		this.dialect = dialect;
	}
}</pre>
<p>3: DB Operation class</p>
<p>All the Database Operation like runQuery etc were implemented in this class</p>
<pre>package com.ricogrid.Utils;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;

public class DBOperations {
	/**
	 * Method is used to run the generated SQL queries
	 *
	 * @param sqlQuery
	 *            -- indicates the given SQL query
	 * @param connection
	 *            -- indicates DB Connection Object
	 * @param limit
	 *            -- to limit query results in some specified range
	 * @param offset
	 *            -- indicates the starting value of limit results
	 * @param rowCount
	 *            -- indicates the total row count
	 * @param paramSize
	 *            -- indicates total number of field names
	 * @return RICO based XML string
	 */
	public static String runQuery(String sqlQuery, Connection connection,
			int limit, int offset, int rowCount, int paramSize ) {

		String ricoGridValue = "";
		PreparedStatement ps = null;
		ResultSet rs = null;

		try {

			ps = connection.prepareStatement(sqlQuery);
			//ps.setMaxRows( limit );
			rs = ps.executeQuery();

			if (rs != null) {
				ricoGridValue = ResponseBuilder.createAjaxResponseForRicoGrid(
						rs, offset, rowCount, paramSize );
			}

		} catch (Exception e) {

			e.printStackTrace();
		} finally {
			try {
				if (ps != null)
					ps.close();
				if (rs != null)
					rs.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return ricoGridValue;
	}

	/**
	 * Method is used to get the total row count
	 *
	 * @param connection
	 *            -- indicates the DB Connection Object
	 * @param sqlString
	 *            -- indicatse the given SQl queries
	 * @return total row count
	 */
	public static int getTotalRowCount(Connection connection, String sqlString ) {

		int rowCount = -1;
		String elementString = "";
		PreparedStatement ps = null;
		ResultSet rs = null;

		sqlString = sqlString.toUpperCase().trim();

		if (sqlString.contains("SELECT "))
			elementString = sqlString.substring(7, sqlString.indexOf(" FROM"))
					.trim();

		sqlString = sqlString.replaceFirst(elementString, " count(*) ");

		try {

			ps = connection.prepareStatement(sqlString);
			rs = ps.executeQuery();

			if (rs != null) {

				if (rs.next())
					rowCount = rs.getInt(1);
			}

		} catch (Exception e) {

			e.printStackTrace();
		} finally {
			try {
				if (ps != null)
					ps.close();
				if (rs != null)
					rs.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return rowCount;
	}

}</pre>
<p>4: MySQLQueryGenerator</p>
<p>This class is used to generate MySQL based SQL query</p>
<pre>package com.ricogrid.Utils;

import java.util.List;
import java.util.Map;
import java.util.Set;

import java.sql.Connection;
public class MySQLQueryGenerator {

	/**
	 * Method to generate the ResponseXML from the given parameters
	 * @param connection -- indicates the Connection Object
	 * @param sqlQuery -- indicates the given SQLQuery
	 * @param paramMap -- contains the request.params object
	 * @param limit -- to limit query results in some specified range
	 * @param offset -- indicates the starting value of limit results
	 * @return a string of generated ResponseXML
	 */
	public static String generateRicoResponseXML(Connection connection, String sqlQuery,
			Map paramMap, int offset, int limit, String dialect) {

		int position = -1;
		int paramElemSize = -1;
		int rowCount = -1;
		String value = "";
		String responseString = "";

		if (connection != null &amp;&amp; paramMap != null &amp;&amp; !"".equals( sqlQuery )) {

			try {

				// parse the given SQL query and to get the field name list from SQLParser.java class
				SQLParser parser = new SQLParser();
				parser.parseSqlQuery(sqlQuery);
				List selectItemList = parser.selectItemList;

				// get the size of field name list
				if (selectItemList != null &amp;&amp; selectItemList.size() &gt; 0)
					paramElemSize = selectItemList.size();

				if (paramMap != null) {

					// iterate parameter Map
					Set set = paramMap.keySet();
					for (String key : set) {

						String prefix = key.substring(0, 1);

						// from here we got the sorting order(ASC/DESC) and the clicked column ID
						if ("s".equals(prefix)) {

							String[] valueArray = (String[]) paramMap.get(key);
							value = valueArray[0].toString();
							position = Integer.parseInt(key.substring(1));

						}
					}
				}

				if (!"".equals(value) &amp;&amp; position != -1) {
					// if sorting
					sqlQuery = createSortingSQLQuery(sqlQuery, limit, offset,
							value, position, selectItemList);
				} else {
					// if scrolling
					sqlQuery = createNormalSQLQuery(sqlQuery, limit, offset);
				}

				if (connection != null &amp;&amp; !"".equals(sqlQuery)) {

					// get the total row count
					rowCount = DBOperations.getTotalRowCount( connection, sqlQuery );

					if ( rowCount != -1 &amp;&amp; paramElemSize != -1 ){
					// run SQL Query and to generate XML String
						responseString = DBOperations.runQuery(sqlQuery,
								connection, limit, offset, rowCount,
								paramElemSize);
					}else{
						responseString = "Your connection with the server was idle for too long and timed out. Please refresh this page and try again";
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return responseString;
	}

	/**
	 * Method is used to create the sorting SQL query
	 *
	 * @param sqlQuery
	 *            -- indicates the given sql query
	 * @param limit
	 *            -- to limit query results in some specified range
	 * @param offset
	 *            -- indicates the starting value of limit results
	 * @param sortOrder
	 *            -- indicates sort order (ASC/DESC)
	 * @param key
	 *            -- indicates the column position to identify the field name
	 * @param elementArray
	 *            -- indicates the list of field names
	 * @return sort query with the given parameters
	 */
	private static String createSortingSQLQuery(String sqlQuery, int limit,
			int offset, String sortOrder, int key, List elementArray) {

		sqlQuery = sqlQuery.toUpperCase().trim();
		String orderByValue = (String) elementArray.get(key);

		if (sqlQuery.contains("ORDER BY "))
			sqlQuery = sqlQuery.substring(0, sqlQuery.indexOf(" ORDER BY"))
					.trim();

		sqlQuery = sqlQuery + " ORDER BY " + orderByValue + " " + sortOrder
				+ " LIMIT " + limit + " OFFSET " + offset;

		return sqlQuery;

	}

	/**
	 * Method to generate normal SQL query with out sorting parameters. ie, SQL
	 * query for scrolling
	 *
	 * @param sqlQuery
	 *            -- indicates given SQL query
	 * @param limit
	 *            -- to limit query results in some specified range
	 * @param offset
	 *            -- indicates the starting value of limit results
	 * @return normal SQL query for scrolling
	 */
	private static String createNormalSQLQuery(String sqlQuery, int limit,
			int offset) {

		String query = "";
		if (!"".equals(sqlQuery))
			sqlQuery = sqlQuery.toUpperCase().trim();
			query = sqlQuery + " LIMIT " + limit + " OFFSET " + offset;

		return query;
	}
}</pre>
<p>5: OracleQueryGenerator</p>
<p>This class is used to generate MySQL based SQL query</p>
<pre>package com.ricogrid.Utils;

import java.util.List;
import java.util.Map;
import java.util.Set;

import java.sql.Connection;
public class OracleQueryGenerator {

	/**
	 * Method to generate the ResponseXML from the given parameters
	 *
	 * @param connection
	 *            -- indicates the Connection Object
	 * @param sqlQuery
	 *            -- indicates the given SQLQuery
	 * @param paramMap
	 *            -- contains the request.params object
	 * @param offset
	 *            -- indicates the starting value of limit results
	 * @param limit
	 *            -- to limit query results in some specified range
	 * @return a string of generated ResponseXML
	 */
	public static String generateRicoResponseXML(Connection connection,
			String sqlQuery, Map paramMap, int offset, int limit, String dialect) {

		int paramElemSize = -1;
		String value = "";
		int position = -1;
		int rowCount = -1;
		String responseString = "";

		if (connection != null &amp;&amp; paramMap != null &amp;&amp; !"".equals(sqlQuery)) {

			try {

				// parse the given SQL query and to get the field name list from
				// SQLParser.java class
				SQLParser parser = new SQLParser();
				parser.parseSqlQuery(sqlQuery);
				List selectItemList = parser.selectItemList;

				// get the size of field name list
				if (selectItemList != null &amp;&amp; selectItemList.size() &gt; 0)
					paramElemSize = selectItemList.size();

				if (paramMap != null) {

					// iterate parameter Map
					Set set = paramMap.keySet();
					for (String key : set) {

						String prefix = key.substring(0, 1);

						// from here we got the sorting order(ASC/DESC) and the
						// clicked column ID
						if ("s".equals(prefix)) {

							String[] valueArray = (String[]) paramMap.get(key);
							value = valueArray[0].toString();
							position = Integer.parseInt(key.substring(1));

						}
					}
				}

				// get the total row count
				if (connection != null &amp;&amp; !"".equals(sqlQuery))
					rowCount = DBOperations.getTotalRowCount(connection,sqlQuery );

				if (!"".equals(value) &amp;&amp; position != -1) {
					// if sorting
					String orderByValue = ( selectItemList.get(position)) != null ? (String) selectItemList.get(position):"";
					sqlQuery = createSQLSortingQuery(sqlQuery, orderByValue,value, offset, limit );
				}else{
					sqlQuery = createNormalSQLQuery( sqlQuery, offset, limit);
				}

				// run SQL Query and to generate XML String
				if (rowCount != -1 &amp;&amp; paramElemSize != -1 &amp;&amp; connection != null &amp;&amp; !"".equals(sqlQuery)) {

					responseString = DBOperations.runQuery(sqlQuery,
								connection, limit, offset, rowCount,
								paramElemSize);
				} else
					responseString = "Your connection with the server was idle for too long and timed out. Please refresh this page and try again";

			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return responseString;
	}

	/**
	 * Method is used to return the sorting SQL query
	 *
	 * @param sqlQuery
	 *            -- indicates the given SQL query
	 * @param orderByValue
	 *            -- indicates the field name for sorting
	 * @param value
	 *            -- sorting order(ASC/DESC)
	 * @param offset
	 *            -- indicates the starting value of limit results
	 * @param limit
	 *            -- to limit query results in some specified range
	 * @return the formatted SQl query as String
	 */
	private static String createSQLSortingQuery(String sqlQuery,
			String orderByValue, String value, int offset, int limit ) throws Exception{

		sqlQuery = sqlQuery.toUpperCase().trim();

		String orderBy = " ORDER BY " + orderByValue + " " + value;

		if (sqlQuery.contains("ORDER BY "))
			sqlQuery = sqlQuery.substring(0, sqlQuery.indexOf(" ORDER BY"))
					.trim();

		sqlQuery += orderBy;

		sqlQuery = generateLimitQuery(sqlQuery, offset, limit);

		return sqlQuery;

	}

	/**
	 * Method to generate normal SQL query with out sorting parameters. ie, SQL
	 * query for scrolling
	 *
	 * @param sqlQuery
	 *            -- indicates given SQL query
	 * @param limit
	 *            -- to limit query results in some specified range
	 * @param offset
	 *            -- indicates the starting value of limit results
	 * @return normal SQL query for scrolling
	 * @throws Exception
	 */
	private static String createNormalSQLQuery(String sqlQuery, int offset, int limit ) throws Exception {

		sqlQuery = sqlQuery.toUpperCase().trim();
		sqlQuery = generateLimitQuery(sqlQuery, offset, limit);

		return sqlQuery;
	}

	/**
	 *  Method is used to create the sorting SQL query
	 * @param sqlQuery -- indicates the given SQL query
	 * @param offset -- indicates the starting value of limit results
	 * @param limit -- to limit query results in some specified range
	 * @return the generated SQL limit Query as String
	 */
	private static String generateLimitQuery(String sqlQuery, int offset, int limit) throws Exception{

		sqlQuery = sqlQuery.toUpperCase().trim();
		boolean isForUpdate = false;
		StringBuffer limitQuery = new StringBuffer(sqlQuery.length() + 150);

		if (sqlQuery.toLowerCase().endsWith(" FOR UPDATE")) {

			sqlQuery = sqlQuery.substring(0, sqlQuery.length() - 11);
			isForUpdate = true;
		}

		limitQuery.append("SELECT * FROM ( SELECT ROW_.*, ROWNUM ROWNUM_ FROM ( ");
		limitQuery.append(sqlQuery);
		limitQuery.append(" ) ROW_ WHERE ROWNUM &lt;= " + (offset + limit)	+ ") WHERE ROWNUM_ &gt; " + offset);

		if (isForUpdate) {
			limitQuery.append(" FOR UPDATE");
		}

		return limitQuery.toString();
	}

}</pre>
<p>5: ResponseBuilder</p>
<p>This class is used to generate the xml using dom4j</p>
<pre>package com.ricogrid.Utils;

import java.io.IOException;
import java.io.StringWriter;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
public class ResponseBuilder {

	// XML format
	public static OutputFormat XML_OUTPUT_FORMAT = OutputFormat.createPrettyPrint();

	/**
	 * Method to create the RICO based XML from the resultset Object
	 * @param resultSet -- indicates the ResultSet Object
	 * @param offset -- indicates the starting value of limit results
	 * @param rowCount -- indicates the total row count
	 * @param paramSize -- indicates total number of field names
	 * @return  RICO based XML string
	 * @throws SQLException
	 */
	public static String createAjaxResponseForRicoGrid(ResultSet resultSet, int offset, int rowCount, int paramSize) throws SQLException {

		Document document = DocumentHelper.createDocument();
		Element ajaxResponse = document.addElement("ajax-response");
		Element response = ajaxResponse.addElement("response");
		response.addAttribute("type", "object");
		response.addAttribute("id", "data_grid_updater");

		Element rows = response.addElement("rows");
		rows.addAttribute("update_ui", "true");
		rows.addAttribute("offset", (offset+1)+"");

		while( resultSet.next() ){

			Element tr_user = rows.addElement("tr");

			for( int i = 1; i&lt;= paramSize; i++){
				tr_user.addElement("td").addText( resultSet.getString(i));
			}

		}
		response.addElement("rowcount").addText( rowCount+"");
		StringWriter stringWriter = new StringWriter();
		XMLWriter writer = new XMLWriter(stringWriter, XML_OUTPUT_FORMAT);
		try {
			writer.write(document);
			writer.close();
			stringWriter.close();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}

		return stringWriter.toString();
	}

}</pre>
<p>6: SQLParser</p>
<p>This class is used to parse the given sql query to various components</p>
<pre>package com.ricogrid.Utils;

import java.util.ArrayList;
import java.util.List;

public class SQLParser {

	public  List selectItemList;
	public  String tableName ;
	public String whereClause;
	public String fromClause;

	public SQLParser() {

		tableName = "";
		whereClause = "";
		fromClause = "";
		selectItemList = new ArrayList();
	}
	/**
	 * Parse a SQL select statement into its major components
  	 * Does not handle:
  	 * 	1) select * from tablename ( use field names instead of * )
  	 * @param sqlQuery
	 * @throws Exception
	 */

	public void parseSqlQuery(String sqlQuery) throws Exception{

		String elementString = "";

		if (!"".equals(sqlQuery)) {
			sqlQuery = sqlQuery.toUpperCase().trim();

			if (sqlQuery.contains("SELECT ")) {
				elementString = sqlQuery
						.substring(7, sqlQuery.indexOf(" FROM")).trim();

				if (!"*".equals(elementString)) {

					String[] elementArray = elementString.split(",");
					for (String element : elementArray){

						if( element.contains( "AS" ))
							element = element.substring(0, element.indexOf("AS")).trim();

						selectItemList.add(element);
					}

				}else{

				}
			}

			if (sqlQuery.contains("FROM ")) {

				if (sqlQuery.contains(" WHERE"))
					tableName = sqlQuery.substring(
							sqlQuery.indexOf(" FROM") + 5,
							sqlQuery.indexOf(" WHERE")).trim();
				else
					tableName = sqlQuery.substring(
							sqlQuery.indexOf(" FROM") + 5).trim();

				fromClause = sqlQuery.substring(sqlQuery.indexOf(" FROM") + 5, sqlQuery.length());
			}

			if( sqlQuery.contains("WHERE")){
				whereClause = sqlQuery.substring( sqlQuery.indexOf( "WHERE ") +5 );
			}

		}
	}

}</pre>
<p>7: db.properties file</p>
<pre>## General parameters
## MySQL/Oracle
dialect 			=Oracle  

## MySQL Connection parameters

#sql.driver 			=com.mysql.jdbc.Driver
#sql.url.datasource      =jdbc:mysql://192.168.0.34:3306/ricogrid
#sql.user			=root
#sql.password		=root

## Oracle Connection parameters

oracle.driver		=oracle.jdbc.driver.OracleDriver
oracle.url.datasource	=jdbc:oracle:thin:@192.168.0.34:1521:XE
oracle.user			=system
oracle.password		=root
</pre>
<p>8: index.jsp</p>
<pre>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;

&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body leftMargin="0" topMargin="0" marginheight="0" marginwidth="0"&gt;
   &lt;table cellspacing="0" cellpadding="0" border="0" width="1374"&gt;
       &lt;tr&gt;
  	   &lt;td align="center" colspan="3"&gt;&lt;iframe name="iframe_MyIFrame" id="iframe_MyIFrame" height="520" width="1375"
                 frameborder="0" src="livegrid.jsp" scrolling="no"&gt;&lt;/iframe&gt;&lt;/td&gt;
      &lt;/tr&gt;
 &lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>9: livegrid.jsp[ for super grid ]</p>
<pre>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;link rel="stylesheet" type="text/css" href="css/main.css"&gt;
&lt;!--[if lte IE 7]&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/ie5-7.css"&gt;
&lt;![endif]--&gt;
&lt;link href="GridShow-Dateien/table.css" type="text/css" rel="stylesheet"&gt;
&lt;style&gt;
	#grid_head{
		font-size: 19px;
	}
&lt;/style&gt;
&lt;/head&gt;
&lt;body leftmargin="0" topmargin="0"
	style="background-color: rgb(236, 240, 246);" marginheight="0"
	marginwidth="0"&gt;

&lt;script src="js/rico/prototype.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="js/rico/rico.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;%
String sqlQuery = "select ID,USER_NAME,CITY from user_details order by user_name";
request.getSession().setAttribute("tblGrid" , sqlQuery);
%&gt;
&lt;script type='text/javascript'&gt;
	Rico.loadModule('LiveGrid', 'LiveGridAjax', 'customgrid.css');
&lt;/script&gt;

&lt;script src="js/rico/ricoSuperGrid.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script&gt;
	var opts = {
		frozenColumns :0,
		defaultWidth :90,
		useUnformattedColWidth :false,
		allowColResize :true, // allow user to resize columns
		windowResize :true, // Resize grid on window.resize event? Set to false when embedded in an accordian.
		useUnformattedColWidth :true,
		scrollBarWidth :19, // this is the value used in positioning calculations, it does not actually change the width of the scrollbar
		hdrIconsFirst :false,
		sortCol :0,
		sortDir :'ASC',
		headingSort :'hover',
		highlightElem :'cursorRow',
		highlightClass :'dataRollOver',
		persistRowClick :true,
		persistantRowClass :'persistantRow',
		minScrollWidth :100, // min scroll area width when width of frozen columns exceeds window width
		canFilterDefault :false,
		canPrint :false,
		columnSpecs : [ {
			type :'number',
			canSort :true
		} ]
	};

	var buffer = null;
	var tblGrid = null;

	Event.observe(window, 'load', function() {

		buffer = new Rico.Buffer.AjaxSQL('/ricoXMLquery?limit=30');
		tblGrid = new Rico.SuperGrid('tblGrid', buffer, opts);
		//tblGrid = new Rico.LiveGrid ('tblGrid', buffer, grid_options);
			tblGrid.options.rowClickHandler = clickMe
					.bindAsEventListener(tblGrid);
			tblGrid.initClickEvents();
		});

function clickMe(e) {
		var cell = Event.element(e);
		cell = RicoUtil.getParentByTagName(cell, 'div', 'ricoLG_cell');
		var newIdx = this.winCellIndex(cell);
		var rowVals = new Array();
		for ( var c = 0; c &lt; this.columns.length; c++) {
			var value = this.columns[c].cell(newIdx.row).textContent;
			rowVals.push(value);
		}

		var rowID = tblGrid.buffer.windowStart + newIdx.row + 1;

		alert("Row Values  :  " + rowVals);
		alert("Selected Row ID : "+ rowID );
	}

	function selectRow(rowId) {
		if (tblGrid != null)
			tblGrid.scrollToSelectRow(rowId - 1);
	}
&lt;/script&gt;

&lt;style&gt;
.dataRollOver {
	background-color: #AABBCC;
}

.persistantRow {
	background-color: orange;
	color: #fff;
}

#rowId{
	border-color: black;
	border-style: solid;
	width: 80px;
}

#serach_img{
	margin-left: 10px;
}

&lt;/style&gt;
&lt;div style="background: steelblue; padding: 10px;"&gt;
&lt;table width="100%"&gt;
	&lt;tr&gt;
		&lt;td width="50%"&gt;
		&lt;div align="left"&gt;&lt;span id ="grid_head"&gt;Rico Live Grid Demo&lt;/span&gt;
		&lt;p class="ricoBookmark"&gt;&lt;span id="tblGrid_bookmark" class="grid_bookmark"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
		&lt;/div&gt;
		&lt;/td&gt;
		&lt;td width="50%"&gt;
			&lt;div align="right"&gt;
				&lt;input type="text" id="rowId" /&gt;
				&lt;img src="images/search_16x16.gif"  id="serach_img" onclick="selectRow($('rowId').value)" alt="Search Row by ID" title="Search Row by ID" /&gt;
			&lt;/div&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;

&lt;/div&gt;

&lt;div class="dataGridHeader"&gt;
&lt;div class="dataGridContent"&gt;
&lt;table class="tableGrid scrolltablestyle" id="tblGrid" name="tblGrid"
	border="0" cellpadding="0" cellspacing="0" width="100%"&gt;

	&lt;thead&gt;
		&lt;tr&gt;
			&lt;th&gt;User ID&lt;/th&gt;
			&lt;th&gt;User Name&lt;/th&gt;
			&lt;th&gt;City&lt;/th&gt;

		&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>10: livegrid.jsp [ for Simple live grid]</p>
<pre>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Rico LiveGrid Plus-Example Demo&lt;/title&gt;

&lt;script src="js/rico/prototype.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script src="js/rico/rico.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;%
String sqlQuery = "select ID,USER_NAME,CITY from user_details order by user_name";
request.getSession().setAttribute("ex3" , sqlQuery);
%&gt;
&lt;script type='text/javascript'&gt;
Rico.loadModule('Effect','LiveGridAjax','LiveGridMenu','greenHdg.css');

var ex3,buffer;

Rico.onLoad( function() {
  // filterUI='t' --&gt; text box
  // filterUI='s' --&gt; select list
  var grid_options = {
    frozenColumns:  1,
    canFilterDefault: false,
    canPrint: true,
    columnSpecs: [{type:'number', canSort:true }]
  };
  buffer=new Rico.Buffer.AjaxSQL('/ricoXMLquery?limit=30');
  ex3=new Rico.LiveGrid ('ex3', buffer, grid_options);

});

&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;p class="ricoBookmark"&gt;
&lt;span id="ex3_bookmark"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;table id="ex3" class="ricoLiveGrid" cellspacing="0" cellpadding="0"&gt;
  &lt;tr&gt;
	  &lt;th&gt;User ID&lt;/th&gt;
	  &lt;th&gt;User Name&lt;/th&gt;
	  &lt;th&gt;City&lt;/th&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>11: web.xml</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
	&lt;display-name&gt;
	RicoLiveGridAutoFetch&lt;/display-name&gt;
	&lt;servlet&gt;
		&lt;description&gt;
		&lt;/description&gt;
		&lt;display-name&gt;RicoXMLQuery&lt;/display-name&gt;
		&lt;servlet-name&gt;RicoXMLQuery&lt;/servlet-name&gt;
		&lt;servlet-class&gt;com.ricogrid.servlets.RicoXMLQuery&lt;/servlet-class&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;RicoXMLQuery&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/ricoXMLquery&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
		&lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
		&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
		&lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
		&lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
		&lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;
&lt;/web-app&gt;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=50&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/12/06/rico-live-grid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>

		<media:content url="http://webbyjava.files.wordpress.com/2008/12/webcontent2.gif" medium="image">
			<media:title type="html">webcontent2</media:title>
		</media:content>

		<media:content url="http://webbyjava.files.wordpress.com/2008/12/webcontent-rico-files-open.gif" medium="image">
			<media:title type="html">webcontent-rico-files-open</media:title>
		</media:content>
	</item>
		<item>
		<title>Basic String Functions</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/basic-string-functions/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/basic-string-functions/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 14:32:37 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Strings]]></category>
		<category><![CDATA[Basic String Functions]]></category>
		<category><![CDATA[String Functions]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=42</guid>
		<description><![CDATA[The Basic String Functions are shown below, concat(String) replace(char, char) length() toLowerCase() toUpperCase() trim() concat(String) This Function is used to concatenate one string onto another. String str1 = new String("Hi "); String str2 = new String("GoodMorning"); String str3 = str1.concat(str2); System.out.println(str3); Output: Hi GoodMorning replace(char, char) This Function is used to replace all occurrences of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=42&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="sample_div_p">The Basic String Functions are shown below,</p>
<ul>
<li>concat(String)</li>
<li>replace(char, char)</li>
<li>length()</li>
<li>toLowerCase()</li>
<li>toUpperCase()</li>
<li>trim()</li>
</ul>
<p><strong>concat(String)</strong></p>
<p class="sample_div_p">This Function is used to concatenate one string onto another.</p>
<div id="code">
<pre>	String str1 = new String("Hi ");
	String str2 = new String("GoodMorning");
	String str3 = str1.concat(str2);
	System.out.println(str3);</pre>
</div>
<p><strong>Output:</strong></p>
<div id="output">Hi GoodMorning</div>
<p><strong>replace(char, char)</strong></p>
<p class="sample_div_p">This Function is used to replace all occurrences of one character with a different character.</p>
<div id="code">
<pre>		String str = new String("Hi GoodMorning ");
		String newStr = str.replace("Morning", "Afternoon");
		System.out.println(newStr);</pre>
</div>
<p><strong>Output:</strong></p>
<div id="output">Hi GoodAfternoon</div>
<p><strong>length()</strong></p>
<p class="sample_div_p">This Function returns the length of the string.</p>
<div id="code">
<pre>		String str = new String("Hi GoodMorning ");
		int strLen = str.length();
		System.out.println(strLen)</pre>
</div>
<p><strong>Output:</strong></p>
<div id="output">15</div>
<p><strong>toLowerCase()</strong></p>
<p class="sample_div_p">This Function converts the entire string to lowercase.</p>
<div id="code">
<pre>		String str = new String("Hi GoodMorning ");
		String lowerStr = str.toLowerCase();
		System.out.println(lowerStr);</pre>
</div>
<p><strong>Output:</strong></p>
<div id="output">hi goodmorning</div>
<p><strong>toUpperCase()</strong></p>
<p class="sample_div_p">This Function converts the entire string to uppercase.</p>
<div id="code">
<pre>		String str = new String("Hi GoodMorning ");
		String upperStr = str.toUpperCase();
		System.out.println(upperStr);</pre>
</div>
<p><strong>Output:</strong></p>
<div id="output">HI GOODMORNING</div>
<p><strong>trim()</strong></p>
<p class="sample_div_p">This Function removes both leading and trailing whitespace from the string.</p>
<div id="code">
<pre>		String str = new String("        Hi GoodMorning        ");
		String trimStr = str.trim();
		System.out.println(trimStr);</pre>
</div>
<p><strong>Output:</strong></p>
<div id="output">Hi GoodMorning</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=42&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/basic-string-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
		<item>
		<title>Strings</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/strings/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/strings/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 14:25:48 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Strings]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=37</guid>
		<description><![CDATA[Java&#8217;s String class allow programmers to search strings,extract parts of them, compare them, etc. There are seven String constructors in java, String str1 = new String(); String str2 = new String(&#8220;Sample String&#8221;); char charArray[] = {&#8216;S&#8217;, &#8216;t&#8217;, &#8216;r&#8217;, &#8216;i&#8217;, &#8216;n&#8217; ,&#8217;g'}; String str3 = new String(charArray); String str4 = new String(charArray, 2, 3); StringBuffer buf [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=37&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Java&#8217;s String class allow programmers to search strings,extract parts of them, compare them, etc. There are seven String constructors in java,</p>
<ul>
<li>String str1 = new String();</li>
<li>String str2 = new String(&#8220;Sample String&#8221;);</li>
<li>char charArray[] = {&#8216;S&#8217;, &#8216;t&#8217;, &#8216;r&#8217;, &#8216;i&#8217;, &#8216;n&#8217; ,&#8217;g'};</li>
<li>String str3 = new String(charArray);</li>
<li>String str4 = new String(charArray, 2, 3);</li>
<li>StringBuffer buf = new StringBuffer(&#8220;buffer&#8221;);</li>
<li>String str5 = new String(buf);</li>
</ul>
<p class="sample_div_p">In the first example, str1 is created as an empty string.The second string, str2, will hold the text &#8220;A New String&#8221;. The next two examples, str3 and str4, are constructed from a character array. In the case of str3, the entire array is placed in the string. For str4, three characters starting in array position two are copied into<br />
the string. Because Java arrays are zero-based, this results in str4 containing &#8220;ray&#8221;. In the final example, the string str5 is constructed from a StringBuffer.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=37&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
		<item>
		<title>String Buffer Operations</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/string-buffer-operations/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/string-buffer-operations/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 14:23:15 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[String Buffer]]></category>
		<category><![CDATA[String Buffer Operations]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=35</guid>
		<description><![CDATA[StringBuffer is a peer class of String that provides much of the functionality of the strings. String represents fixed-length, immutable character sequences.In contrast StringBuffer represents growable and writable character sequences. String buffers are preferred when heavy modification of character strings is involved (appending,inserting, deleting, modifying etc).Strings can be obtained from string buffers. Since the StringBuffer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=35&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>StringBuffer is a peer class of String that provides much of the functionality of the strings. String represents fixed-length, immutable character sequences.In contrast StringBuffer represents growable and writable character sequences. String buffers are preferred when heavy modification of character strings is involved (appending,inserting, deleting, modifying etc).Strings can be obtained from string buffers. Since the StringBuffer class does not override the equals() method from the Object class, contents of string buffers should be converted to String objects for string comparison.A StringIndexOutOfBoundsException is thrown if an index is not valid when using wrong index in String Buffer manipulations.The StringBuffer<br />
provides 3 constructors which create, initialize and set the initial capacity of StringBuffer objects.</p>
<p><strong>StringBuffer Constructors</strong></p>
<div id="code">
<pre>public class TestStringBuffer {

  public static void main(String[] args) {

	StringBuffer stringBuffer = new StringBuffer("Test StringBuffer");
	StringBuffer stringBufferWithFixedSize = new StringBuffer(500);
	StringBuffer stringBufferWithDefaultSize = new StringBuffer(); //Default Constructor
	System.out.println("StringBuffer : " + stringBuffer);
	System.out.println("StringBuffer with Fixed Size capacity : " + stringBufferWithFixedSize.capacity());
	System.out.println("StringBuffer with Default Size capacity : " + stringBufferWithDefaultSize.capacity());
  }
}</pre>
</div>
<div id="output">
<pre>	StringBuffer : Test StringBuffer
	StringBuffer with Fixed Size capacity : 500
	StringBuffer with Default Size capacity : 16</pre>
</div>
<p><strong>String Buffer Functions</strong></p>
<ul>
<li><strong>capacity() -: </strong>
<p class="sample_div_p">Returns the current capacity<br />
of the String buffer.</li>
<li><strong>length() :- </strong>
<p class="sample_div_p">Returns the length (character count)<br />
of this string buffer.</li>
<li><strong>charAt(int index) :-</strong>
<p class="sample_div_p">The specified character of the sequence currently<br />
represented by the string buffer, as indicated by the index argument, is returned.</li>
<li><strong>setCharAt(int index, char ch) :- </strong>
<p class="sample_div_p">The character at the<br />
specified index of this string buffer is set to ch</li>
<li><strong>toString() :- </strong>
<p class="sample_div_p">Converts to a string representing the data<br />
in this string buffer</li>
<li><strong> insert(int offset, char c) :- </strong>
<p class="sample_div_p">Inserts the string representation<br />
of the char argument into this string buffer.</li>
<li><strong>delete(int start, int end) :- </strong>
<p class="sample_div_p">Removes the characters in a substring<br />
of this StringBuffer</li>
<li><strong>replace(int start, int end, String str) :- </strong>
<p class="sample_div_p">Replaces the<br />
characters in a substring of this StringBuffer with characters in the specified String.</li>
<li><strong>reverse() :- </strong>
<p class="sample_div_p">The character sequence contained in this string buffer<br />
is replaced by the reverse of the sequence.</li>
<li><strong>append(String str) :- </strong>
<p class="sample_div_p">Appends the string to this string buffer.</p>
</li>
</ul>
<div id="code">
<pre>public class TestStringBuffer {

  public static void main(String[] args) {

	StringBuffer stringBuffer = new StringBuffer("Test String Buffer");
	StringBuffer stringBufferWithFixedSize = new StringBuffer(100);
	StringBuffer stringBufferWithDefaultSize = new StringBuffer();

	//StringBuffer function capacity()
	System.out.println("StringBuffer : " + stringBuffer);
	System.out.println("StringBuffer capacity : " + stringBuffer.capacity());
	System.out.println("StringBuffer with Fixed Size capacity : " + stringBufferWithFixedSize.capacity());
	System.out.println("StringBuffer with Default Size capacity : " + stringBufferWithDefaultSize.capacity());

	//StringBuffer function length()
	System.out.println("stringBuffer length : " + stringBuffer.length());

	//StringBuffer function charAt()
	System.out.println("stringBuffer charAt 2 : " + stringBuffer.charAt(2));

	//StringBuffer function setCharAt()
	stringBuffer.setCharAt(1, 'E');
	System.out.println("stringBuffer after setCharAt 1 to E is : "+ stringBuffer);

	//StringBuffer function toString()
	System.out.println("StringBstringBufferuffer toString() is : " + stringBuffer.toString());

	//StringBuffer function append()
	stringBufferWithDefaultSize.append("Test Buffer");
	System.out.println("stringBufferWithDefaultSize when appended with a String : "+ stringBufferWithDefaultSize.toString());

	//StringBuffer function insert()
	stringBufferWithDefaultSize.insert(1, 'C');
	System.out.println("stringBufferWithDefaultSize when C is inserted at 1 : "	+ stringBufferWithDefaultSize.toString());

	//StringBuffer function delete()
	stringBufferWithDefaultSize.delete(1, 'C');
	System.out.println("stringBufferWithDefaultSize when C is deleted at 1 : "+ stringBufferWithDefaultSize.toString());

	//StringBuffer function reverse()
	stringBufferWithDefaultSize.reverse();
	System.out.println("Reversed stringBufferWithDefaultSize : " + stringBufferWithDefaultSize);

	//StringBuffer function setLength()
	stringBufferWithFixedSize.setLength(5);

	stringBufferWithFixedSize.append("Sample Buffer");
	System.out.println("stringBufferWithFixedSize : " + stringBufferWithFixedSize);

	}
  }</pre>
</div>
<p><strong>Output:</strong></p>
<div id="code">
<pre>	StringBuffer : Test String Buffer
	StringBuffer capacity : 34
	StringBuffer with Fixed Size capacity : 100
	StringBuffer with Default Size capacity : 16
	stringBuffer length : 18
	stringBuffer charAt 2 : s
	stringBuffer after setCharAt 1 to E is : TEst String Buffer
	StringBstringBufferuffer toString() is : TEst String Buffer
	stringBufferWithDefaultSize when appended with a String : Test Buffer
	stringBufferWithDefaultSize when C is inserted at 1 : TCest Buffer
	stringBufferWithDefaultSize when C is deleted at 1 : T
	Reversed stringBufferWithDefaultSize : T
	stringBufferWithFixedSize : Sample Buffer</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=35&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/string-buffer-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
		<item>
		<title>Copy Characters using BufferedStream</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/copy-characters/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/copy-characters/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 14:11:24 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Copy Files[ characters ]]]></category>
		<category><![CDATA[BufferedStream]]></category>
		<category><![CDATA[Copy Characters]]></category>
		<category><![CDATA[Copy Characters using BufferedStream]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=28</guid>
		<description><![CDATA[Buffered input streams read data from a memory area known as a buffer;the native input API is called only when the buffer is empty. Similarly,buffered output streams write data to a buffer, and the native output API is called only when the buffer is full. Example import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=28&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Buffered input streams read data from a memory area known as a buffer;the native input API is called only when the buffer is empty. Similarly,buffered output streams write data to a buffer, and the native output API is called only when the buffer is full.<br />
<strong>Example</strong></p>
<div id="code">
<pre>import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class CopyFiles {

  public static void main(String[] args){
	  String sourceFileName = "D:\\Test Folder\\Test File.txt";
	  String destinationFileName = "D:\\Test Folder\\Test File 1.txt";
	  copyFile(sourceFileName, destinationFileName);
  }	

 private static void copyFile(String sourceFileName,String destinationFileName) { 

      BufferedReader br = null;
      BufferedWriter bw = null; 

      try {
      	br = new BufferedReader(new FileReader( sourceFileName ));
      	bw = new BufferedWriter(new FileWriter( destinationFileName ));
        int c;
        while ((c = br.read()) != -1)  {
           bw.write(c);
        }
        br.close();
        bw.close();
      }catch (Exception e) {
	  e.printStackTrace();
      }
}</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=28&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/copy-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
		<item>
		<title>Copy Files[ line by line ]</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/copy-files-2/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/copy-files-2/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 14:07:17 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Copy Files]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=26</guid>
		<description><![CDATA[Invoking readLine returns a line of text with the line CopyLines outputs each line using println, which appends the line terminator for the current operating system.This might not be the same line terminator that was used in the input file. Example import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; public class CopyFiles { public static [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=26&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Invoking readLine returns a line of text with the line CopyLines outputs each line using println, which appends the line terminator for the current operating system.This might not be the same line terminator that was used in the input file.<br />
<strong>Example</strong></p>
<div id="code">
<pre>import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class CopyFiles {

  public static void main(String[] args){
	  String sourceFileName = "D:\\Test Folder\\Test File.txt";
	  String destinationFileName = "D:\\Test Folder\\Test File 1.txt";
	  copyFile(sourceFileName, destinationFileName);
  }	

 private static void copyFile(String sourceFileName,String destinationFileName) { 

      BufferedReader br = null;
      PrintWriter pw = null; 

      try {
          br = new BufferedReader(new FileReader( sourceFileName ));
    	  pw =  new PrintWriter(new FileWriter( destinationFileName ));

          String line;
          while ((line = br.readLine()) != null) {
              pw.println(line);
          }

          br.close();
          pw.close();
      }catch (Exception e) {
	  e.printStackTrace();
      }
}</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=26&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/copy-files-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
		<item>
		<title>Copy Files[ characters ]</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/copy-files-characters/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/copy-files-characters/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 14:04:40 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Copy Files]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=24</guid>
		<description><![CDATA[CopyCharacters is very similar to CopyBytes. The most important difference is that CopyCharacters uses FileReader and FileWriter for input and output in place of FileInputStream and FileOutputStream in CopyCharacters, the int variable holds a character value in its last 16 bits; in CopyBytes, the int variable holds a byte value in its last 8 bits. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=24&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>CopyCharacters is very similar to CopyBytes. The most important difference is that CopyCharacters uses FileReader and FileWriter for input and output in place of FileInputStream and FileOutputStream in CopyCharacters, the int variable holds a character value in its last 16 bits; in CopyBytes, the int<br />
variable holds a byte value in its last 8 bits.<br />
<strong>Example</strong></p>
<div id="code">
<pre>import java.io.FileReader;
import java.io.FileWriter;

public class CopyFiles {

  public static void main(String[] args){
	  String sourceFileName = "D:\\Test Folder\\Test File.txt";
	  String destinationFileName = "D:\\Test Folder\\Test File 1.txt";
	  copyFile(sourceFileName, destinationFileName);
  }	

 private static void copyFile(String sourceFileName,String destinationFileName) { 

      FileReader reader = null;
      FileWriter writer = null;
      try{
          reader = new FileReader( sourceFileName );
          writer = new FileWriter( destinationFileName );

          int c;
          while ((c = reader.read()) != -1)  {
              writer.write(c);
          }
          reader.close();
          writer.close();
      }catch (Exception e) {
	  e.printStackTrace();
      }
}</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=24&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/copy-files-characters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
		<item>
		<title>Create Temporary Files</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/temporary-files/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/temporary-files/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 14:02:45 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Create Temporary Files]]></category>
		<category><![CDATA[Temporary Files]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=22</guid>
		<description><![CDATA[Create a temporary file whose name is guaranteed to be unique. You specify a prefix, suffix and directory to use. Always name your temporary files with a prefix temp and a suffix .tmp,so that they can easily be scavenged and deleted after a crash by generic junk cleaning utilities. The file will not be automatically [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=22&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Create a temporary file whose name is guaranteed to be unique.<br />
You specify a prefix, suffix and directory to use. Always name your temporary files with a prefix<br />
temp and a suffix .tmp,so that they can easily be scavenged and deleted after a crash by<br />
generic junk cleaning utilities. The file will not be automatically deleted on exit, unless you use<br />
deleteOnExit.<br />
<b>Example:</b></p>
<div id='code'>
<pre>
import java.io.File;

public class CreateTempFile {

  public static void main(String[] args){
	try {
		File temp = File .createTempFile( "temp", ".tmp", new File( "D:\\" ) );
		temp.deleteOnExit();
	} catch (Exception e) {
		e.printStackTrace();
	}
  }
}
</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=22&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/temporary-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
		<item>
		<title>Copy Files [byte by byte ]</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/copy-files/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/copy-files/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 14:01:24 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Copy Files]]></category>
		<category><![CDATA[file copy]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=19</guid>
		<description><![CDATA[CopyBytes spends most of its time in a simple loop that reads the input stream and writes the output stream one byte at a time.The following example illustrates, how to copy a file in to another File. Example import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; public class CopyFiles { public static void main(String[] args){ String sourceFileName [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=19&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>CopyBytes spends most of its time in a simple loop that reads the input stream and writes the output stream one byte at a time.The following example illustrates, how to copy a file in to another File.<br />
<strong>Example</strong></p>
<div id="code">
<pre>import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class CopyFiles {

  public static void main(String[] args){
	  String sourceFileName = "D:\\Test Folder\\Test File.txt";
	  String destinationFileName = "D:\\Test Folder\\Test File 1.txt";
	  copyFile(sourceFileName, destinationFileName);
  }	

 private static void copyFile(String sourceFileName,String destinationFileName) { 

	 int i;
	 FileInputStream fin;
	 FileOutputStream fout;

	 try {
		 fin = new FileInputStream(new File( sourceFileName ));
		 fout = new FileOutputStream(new File( destinationFileName ));
		 do {
			 i = fin.read();
			 if(i != -1)
				 fout.write(i);
		 } while(i != -1);

		 fin.close();
		 fout.close();

	 } catch(Exception e) {
		 e.printStackTrace();
	 }
   }
}</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=19&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/copy-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing Files</title>
		<link>http://webbyjava.wordpress.com/2008/11/26/writing-files/</link>
		<comments>http://webbyjava.wordpress.com/2008/11/26/writing-files/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 13:59:53 +0000</pubDate>
		<dc:creator>baiju43</dc:creator>
				<category><![CDATA[Writing Files]]></category>
		<category><![CDATA[Writing Files using java]]></category>

		<guid isPermaLink="false">http://webbyjava.wordpress.com/?p=17</guid>
		<description><![CDATA[The following example illustrates, how to write contents in to a File. Example import java.io.FileOutputStream; import java.io.PrintStream; public class TestConsoleInput { public static void main(String[] args){ String destinationFileName = "D:\\Test Folder\\Test File 1.txt"; writeFile(destinationFileName); } private static void writeFile(String destinationFileName) { FileOutputStream out; PrintStream pw = null; try { out = new FileOutputStream( destinationFileName ); [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=17&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following example illustrates, how to write contents in to a File.<br />
<strong>Example</strong></p>
<div id="code">
<pre>import java.io.FileOutputStream;
import java.io.PrintStream;

public class TestConsoleInput {

  public static void main(String[] args){
	  String destinationFileName = "D:\\Test Folder\\Test File 1.txt";
	  writeFile(destinationFileName);
  }	

 private static void writeFile(String destinationFileName) { 

     FileOutputStream out;
     PrintStream pw = null;
     try
     {
       out = new FileOutputStream( destinationFileName );
       pw = new PrintStream( out );
       pw.println ("Hi Friends GoodMorning!!");
       pw.close();
     }
     catch (Exception e)
     {
       e.printStackTrace();
     }
}
}</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/webbyjava.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/webbyjava.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/webbyjava.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/webbyjava.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/webbyjava.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/webbyjava.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/webbyjava.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/webbyjava.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/webbyjava.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/webbyjava.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/webbyjava.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/webbyjava.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/webbyjava.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/webbyjava.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=webbyjava.wordpress.com&amp;blog=5650397&amp;post=17&amp;subd=webbyjava&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://webbyjava.wordpress.com/2008/11/26/writing-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/aa8dc591ef307e0927258508336649bc?s=96&#38;d=identicon" medium="image">
			<media:title type="html">baiju43</media:title>
		</media:content>
	</item>
	</channel>
</rss>
