This sample demonstrates how to retrieve the contents of a file (data set member or sequential data set) on the MVS™ file system.
To retrieve the content for the resource, make sure the resource is selected in the navigator, then select the API Samples > Get File Contents action.

The contents in the file are displayed in the standard output associated with the workbench. This can be found in the DOS window from which the workbench was started, or in the Console view of the hosting workbench in the case of the runtime workbench.

The complete source code can be found at GetContentsAction.java.
The following code snippet from the run method of the class GetContentsAction demonstrates how to obtain the content of an MVS file (PDS member or sequential data set). The snippet differentiates between an IPhysicalFile and an ILogicalFile, but the overall flow is the same for both. The code first invokes the getContents method to obtain an InputStream. Once you have an InputStream, the standard Java™ methods such as read can be invoked to retrieve the content of the file.
InputStream is = null;
if (selectedItem instanceof ILogicalFile) {
// Project proxy for resource
ILogicalFile file = (ILogicalFile) selectedItem;
filename = file.getName();
is = file.getContents();
} else if (selectedItem instanceof IPhysicalFile) {
// Physical Resource
IPhysicalFile file = (IPhysicalFile) selectedItem;
filename = file.getName();
is = file.getContents();
}
int ch = is.read();
while (ch != -1) {
System.out.write(ch);
ch = is.read();
}
This example also demonstrates how to react to selection change events in Eclipse. The GetContentsAction class implements the ISelectionListener interface. Its selectionChanged method implementation reacts to events referring to an IStructuredSelection, typically caused by a change in the current selection in a tree navigator. The example code iterates through all the items contained in the current selection using an iterator associated with it and adding each item to a list.
public void selectionChanged(IAction action, ISelection selection) {
fTargetList = null;
if (selection instanceof IStructuredSelection) {
fTargetList = new ArrayList();
IStructuredSelection selections = (IStructuredSelection)
selection;
for (Iterator e = selections.iterator(); e.hasNext();) {
Object next = e.next();
fTargetList.add(next);
}
}
}