Posts

Showing posts from April, 2012

Java Code To Read XML File

GetData.java import java.io.*; import org.w3c.dom.*; import org.xml.sax.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; public class GetData { public static void main(String[] arg) { try { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter XML file name: "); String xmlFile = bf.readLine(); File file = new File(xmlFile); if (file.exists()) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(xmlFile); //Create transformer Transformer transFormerObj = TransformerFactory.newInstance().newTransformer(); //Output text type transFormerObj.setOutputProperty(OutputKeys.METHOD, "text"); //Write the document to a file ...

Java Code to Read Excel File Without Using DSN

import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Locale; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.WorkbookSettings; import jxl.read.biff.BiffException; import jxl.DateCell; public class ReadXLSheet { public void init(String filePath) { FileInputStream fs = null; try { fs = new FileInputStream(new File(filePath)); contentReading(fs); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }finally { try { fs.close(); } catch (IOException e) { e.printStackTrace(); } } } //Returns the Headings used inside the excel sheet public void getHeadingFromXlsFile(Sheet sheet) { int columnCount = sheet.getColumns(); for (int i = 0; i System.out.println(sheet.getCell(i, 0).getContents()); } } public void contentReading(InputStream fileInputStream) throws BiffExce...

Limiting the number of characters in Textarea using jQuery

<html> <style type="text/css"> #mainDiv{background-color:skyblue;-moz-border-radius:5px 5px;width:200;-moz-box-shadow:2px 2px 3px 000;padding:2px} #targetDiv{background-color:yellow;-moz-border-radius:5px 5px;width:200;-moz-box-shadow:2px 2px 3px 000;padding:2px} </style> <script src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ var limit=10; $('#comments').keyup(function(){ if($('#comments').val().length<=limit) { $('#targetDiv').html(limit-$('#comments').val().length+"   Character Left"); } if($('#comments').val().length>limit) { $('#comments').val($('#comments').val().substring(0,limit)); } }) }); </script> <body> <div id="mainDiv"><center> <textarea id="comments"></textarea> </div...

Java Code to Print Even or Odd without using Loop And IF condition

import java.io.*; public class EvenOrOdd { public static void main(String arg[])throws IOException { String arr[]={"Even","Odd"}; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int number; System.out.println("Enter number to check"); number=Integer.parseInt(br.readLine()); number=number%2; System.out.println("Entered number is "+arr[number]); } }

Java Code to Print Even or Odd without using Loop And IF condition

import java.io.*; public class EvenOrOdd { public static void main(String arg[])throws IOException { String arr[]={"Even","Odd"}; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int number; System.out.println("Enter number to check"); number=Integer.parseInt(br.readLine()); number=number%2; System.out.println("Entered number is "+arr[number]); } }