This simple z/OS Java application uses the JZOS toolkit to open and read a z/OS data set and print its contents to standard output.

Create a Java source file named under the src directory of our Insurance project and copy and paste the following sample code into the Java source file.


 * Sample program that reads z/OS data set containing insurance
 * payee data and prints directly to standard output.
 * @see

public class ReadPayeeData {
    public static void main(String[] args) throws Exception {       
        // Grab the name of the z/OS data set to read
        // insurance payee data from. This information is supplied
        // as an argument to this Java application.
        String datasetName;
        if (args.length == 1) {
            datasetName = args[0];
        } else {
                    "Please provide the data set name "
                    + "containing payee payout information");
        // Construct a JZOS ZFile object.
        // This will open the specified z/OS data set
        // for read in binary mode, reading one record
        // at a time, and reading in sequential mode to
        // increase I/O performance.
        ZFile zFile = new ZFile(

                "//'" + datasetName + "'", "rb,type=record,noseek");
        // The following block of code reads from the
        // z/OS data set one record at a time, printing
        // the data read to standard output.
        try {
            int nRead;
            byte[] record = new byte[zFile.getLrecl()];
            while((nRead = >= 0) {
                String recordString = new String(
        } finally {

  • This is what our project should look like:
  • write_1

    Notice the red (x) overlaid on top of our Java source file. This means that Eclipse wasn’t able to compile our Java source due to compilation errors.

  • Open the Problems view in our Eclipse IDE and we should see these compile errors:
  • write_2

    What these errors tell us is that Eclipse can’t resolve the JZOS toolkit classes that we are calling in our sample application. We need to tell Eclipse about the JZOS toolkit.

  • To tell Eclipse to include the JZOS toolkit in our project, first copy the ibmjzos.jar file that we downloaded in the Setup section into
  • write_3

    Then open up the project properties window by right-clicking on our Insurance project and click on Properties from the context menu. On the Properties for Insurance window, click on Java Build Path on the left side and the Libraries tab on the right.


    Click on Add JARs… and navigate to our ibmjzos.jar under the lib directory of our Insurance project, and click OK:


  • We should see the following in our Java Build Path:
  • write_6

    Click OK and we should see the following in our Package Explorer view:


    The red (x) overlay is now gone. There are no compile errors or warning, and our Insurance project has compiled successfully.

Join The Discussion

Your email address will not be published. Required fields are marked *