Read and Write excel using java

You can Read and Write excel using java. We will use Workbook – JExcelApi to read and write an excel sheet.

Download Workbook – JExcelApi from

We are using eclipse for this example. We will see 3 examples in this tutorial:
1. Read cells/data from the Excel file
2. Create a new file and write data to the newly created file
3. Write data to the existing excel file

Package Explorer Excel Manipulation

So, let’s pick the first example i.e. Read cells/data from the Excel file To start with this program you need an excel sheet to read. so, for this program to run we have added a folder “excelsheet” in the project’s root and kept an excel file with name “testsheet.xls”. We will read this file using the below program.


Example 2 (Create a new file and write data to the newly created file) In this example, we will write the code to create an excel sheet then, write data in few cells


Example 3 (Write data to the existing excel file) Suppose you have an existing excel sheet in which you have to write the new content or replace the existing one then you can also do that. Below example illustrate, how to write data to the existing excel file.

Download the Project with all three class files

How to open a program like notepad, pdf file using Java?

Java program to open any program or file.
Example(s) –
1. Open notepad program using java.
2. Open a pdf file using java.

This example will open a notepad for you.


This is a sample example to open a pdf file using java.

To do so you just need to write some java programming.

Here is the example:



The java.lang.Process.waitFor() method causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the sub-process has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the sub-process exits.

The ProcessBuilder.start() and Runtime.exec methods create a native process and return an instance of a subclass of Process that can be used to control the process and obtain information about it. The class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process. Click to Know more…

Run jar file from bat file

You need a executable jar file. See how to create a jar file


Get the demo jar

Once your jar file is ready.

Step 1: Create a bat file with any name.

Step 2: Write the following line in you bat file.

If you want to hold the black screen. Use the following code

Now run the bat file and it will start you jar file

Main Class

How to create an executable jar file using eclipse

You can do this by using eclipse.

Step 1: Create a project. I have created a project with name “autorun”

Step 2: Right click on project > select Export
You will see export options select JAR file, then click next

jar export
Step 3:
Select the resource to export. Give export destination.

jar file specification
Step 4: Click Next.

Step 5: Specify the “main class” that you want to execute when someone clicks on the jar file (it is a starting point) , then Click Finish

Main Class

Done. Now Double click on the jar and it will run.