Templates by BIGtheme NET

Java Program to read .PST and .OST files

In this Article, I will show you simple java program to read micro soft files
with .pst and .ost extension.

Tools Uses :

1) eclipse version Luna 4.4.1.
2) Maven 3.3.3
3) JDK 1.6 or higher

Simple Java program to read .ost and .pst files.

Simple Steps to follow,

1) Create a maven project.
2) Add java-libpst dependency to pom.xml file
3) Write a simple program to read .pst and .ost files.
4) Demo, run and verify the out put

Dependency that need to be added to pom.xml file is,


Complete pom.xml file will be as given,
After adding the dependency.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">






Write a simple program to read .pst and .ost files

1) Create pstFile Object, by passing the pst file as argument.

 PSTFile pstFile = new PSTFile(filename); 

2) Get the root folder by calling the method getRootFolder()


3) Get SubFolder list by calling getSubFolders() method

 Vector<PSTFolder> childFolders = folder.getSubFolders(); 

4) Get PSTMessage by type casting the child to PSTMessage class.

 PSTMessage email = (PSTMessage)folder.getNextChild(); 

5) There are simple methods are in PSTMessage class to get email details.
like email Subject, email body, email body in Html format, recipient list…etc.

Here is complete java source code,

package com.devjavasource.email.readOstPstFiles;

import com.pff.*;
import java.util.*;

 * Hello world!
public class App 

	public static void main(String[] args)
		//final String finalName = "C:/Venkat_06012014/Blog/eMails/pst/nallave_ost_format.ost";
		final String finalName = "C:/Venkat_06012014/Blog/eMails/pst/nalla.pst";
		new App( finalName );

	public App(String filename) {
		try {
			PSTFile pstFile = new PSTFile(filename);			
		} catch (Exception err) {

	int depth = -1;
	public void processFolder(PSTFolder folder)
			throws PSTException, java.io.IOException
		// the root folder doesn't have a display name
		if (depth > 0) {

		// go through the folders...
		if (folder.hasSubfolders()) {
			Vector<PSTFolder> childFolders = folder.getSubFolders();
			for (PSTFolder childFolder : childFolders) {

		// and now the emails for this folder
		if (folder.getContentCount() > 0) {
			PSTMessage email = (PSTMessage)folder.getNextChild();
			while (email != null) {
				System.out.println("Email Subject: "+email.getSubject());
				System.out.println("Email Body: "+email.getBodyHTML());
				//System.out.println("Email Body: "+email.getDisplayName());
				email = (PSTMessage)folder.getNextChild();

	public void printDepth() {
		for (int x = 0; x < depth-1; x++) {
			System.out.print(" | ");
		System.out.print(" |- ");

Select App.java and “Run As” -> “Java Application”

 |- Top of Outlook data file
 |  |- Deleted Items
 |  |- test
 |  |  |- Email Subject: Tagging N4 -
 |- Search Root
 |- SPAM Search Folder 2

You can download complete project, Here

*** Venkat – Happy learning ****