Monday, November 26, 2012

Writing a file using CreateJavaObject in peoplesoft peoplecode


I was trying to create a peoplesoft program which would use java objects to create an output file, as Java objects can be used to create binary files in peoplesoft. So here is the code:

Local JavaObject &jFile;
Local JavaObject &msg;
&msg = CreateJavaObject("java.lang.String", "Hello World!");

Local JavaObject &buf = &msg.getBytes();
Local number &byteCount = &buf.length;
&jFile = CreateJavaObject("java.io.FileOutputStream", "C:\Temp\java.txt", True);
&jFile.write(&buf, 0, &byteCount);
&jFile.close();

The key here is to keep in mind that we are dealing with java objects in peoplesoft, Hence we must use java functions and java classes.