Parsing / Reading XLS -XLSX -CSV-XML file in Java
Export Grid View to Excel in Servlet and Jsp
Exporting contents to excel spreadsheet is a much required functionality for almost every data driven website. In this article I am going to explain in detail on how to export gridview contents to an excel sheet via a java web application. Project Structure Servlet package servlet; import java.io.IOException; import java.util.ArrayList; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import...
read moreCompare two files by content in Java
In this tutorial, we will provide a simplified approach to compare two files in Java by content. We will use Apache Commons IO library to perform this comparison, and run this against some test files we prepare to see the results. Before start download commons-io-2.4.jar and add in your classpath. We will use the contentEquals() method of the FileUtils class of the above library to compare the file content. The Java program to compare two files by content using Apache Commons IO, is provided...
read moreSplitting PDF File Using Java iText API
Previously I wrote a tutorial about how to merge two or more PDF files. This tutorial we will learn about splitting a PDF with multiple pages into multiple PDFs using the Java iText API. Library Required itext-2.1.4.jar File: SplitPDF.java package com.simplecode.util; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfImportedPage; import...
read moreMerge PDF files using java iText
Library Required itext-2.1.4.jar File: MergePDF.java package com.simplecode.util; //Please include the itext-2.1.4.jar in the classpath import java.util.List; import java.util.Iterator; import java.util.ArrayList; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import com.lowagie.text.Document; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.PdfReader; import...
read moreHow To Change The File Last Modified Date In Java?
Hereâs an example to change the fileâs last modified date with the help of File.setLastModified() . This method accept the new modified date in milliseconds (long type), So some data type conversion are required. import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class ChangeFileLastModifiedDate { public static void main(String[] args) { try { File file = new File("C:\\File.pdf"); // Print the original last modified...
read moreHow To Get The File’s Last Modified Date & time In Java?
In Java, you can use the File.lastModified() to get the file’s last modified timestamps. This method will returns the time in milliseconds (long value), you may to format it with SimpleDateFormat to make it a human readable format. File Last Modified Date and Time import java.io.File; import java.text.SimpleDateFormat; public class GetFileLastModifiedDate { public static void main(String[] args) { File file = new File("c:\\Core java.ppt"); System.out.println("Before Format : " +...
read moreHow to find or check hidden files in Java ?
we can check the file property is hidden or not and accordingly we can use that file in our application. isHidden() method is provided on file Class in Java which we will use to test this property. Syntax of the method: public static boolean isHidden(Path path) throws IOException Here we pass the path of the file for which we want to test hidden property and it will return true if it’s a hidden file otherwise will get false value. Here is complete code example of finding hidden file in Java, we are using...
read moreRSS feeds Using Java
RSS feeds are always becoming used more and more. Using RSS feeds is a good way to keep updated on a particular subject, it is also a very good way to keep a website always updated without the need of manual updates. RSS feeds are very easy to install into a website and with their help, your website will never be out of date! In order to add RSS feeds to your website, the below code can be used Assuming we want the latest RSS feeds about sports. We would primarily need the URL of the feeds. In our case we will be using the...
read moreJava code to convert xlsx & xls to csv
Note : This Program uses XSSFWorkbook for xlsx and HSSFWorkbook for xlx. package com.simplecode.excel; import java.io.*; import java.util.Iterator; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; class ExcelToCSV { static void convertToXlsx(File inputFile, File outputFile)...
read moreJava Code to Convert XLSX to CSV Files
Note : xlsx file should contain only data in cells. No image and any other media element. This program has been developed only for cell data package com.simplecode.excel; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Iterator; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; class XlsxtoCSV { static void xlsx(File...
read more