Donwloaded Cryptix OpenPGP which is a Java implementation of the OpenPGP standard and tried a sample to encrypt and decrypt a text file.
//First read the key.
FileInputStream in = new FileInputStream(keyPath);
MessageFactory mf = MessageFactory.getInstance("OpenPGP");
Collection msgs = mf.generateMessages(in);
KeyBundleMessage kbm = (KeyBundleMessage)msgs.iterator().next();
bundle = kbm.getKeyBundle();
in.close();
// Build the literal message
LiteralMessage litmsg = null;
BufferedReader in = new BufferedReader(new FileReader(filePath+toEncryptFile));
String str;
while ((str = in.readLine()) != null) {
msg = msg + str+"\n";
}
in.close();
// Encrypt the message.
Message msg = null;
EncryptedMessageBuilder emb =
EncryptedMessageBuilder.getInstance("OpenPGP");
emb.init(litmsg);
emb.addRecipient(bundle);
msg = emb.build();
// Armour the message and write it to disk
PGPArmouredMessage armoured;
armoured = new PGPArmouredMessage(msg);
FileOutputStream out = new FileOutputStream(filePath+encryptFileName);
out.write(armoured.getEncoded());
out.close();