At run time you usually need to get only the name of the file. The file name is guaranteed to be an absolute path, and all parameter or root directory substitutions will already have been done. For an INPUT file parameter the file will exist and will already contain the data described by the Handler. For an OUTPUT file parameter the file will usually not exist but the directory for the file will exist. ScalarVariable fileVar = runEnv.getContext().getScalarParameter("myFile"); FileValueType fileValue = (FileValueType)fileVar.getValueObj(); String fileName = fileValue.getLocalFileName(); The component Executor can then open the file for reading for an INPUT
parameter or writing for an OUTPUT parameter. Binary files should be
accessed through a It is usually necessary to check for an IOException on the open. An IOException indicates the file does not exist or is unreadable and usually causes the component to fail. FileInputStream fileStream; try { fileStream = new FileInputStream(fileName); } catch (IOException ex) { throw new RtException(ex); } It is occasionally necessary to set the local file name for an OUTPUT
file parameter at run time. You will have to set the local file name
if the component runs an external program that writes a file with a name
that cannot be determined at design time. The Component Executor determines
where the file was written, usually by examining the output of the program,
and sets the local name of an OUTPUT file parameter to the path to the
file. Setting the local file name can be done for any output setting
of the String outPath = getPathFromProgramOutput(); fileValue.setLocalFileName(outPath);
As a convenience in reading or writing a Text file that may have been
configured with a specific file encoding, |