×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
HI! All,
I am new to the AS/400 world and would sincerely appreciate any help I can
get for the following.
I want to write a java class (which would run on the AS/400) that would
accept a fileName, fileMemberName and pContents. The class should then
create a file with the fileName, if it does not already exist and then add a
member with name fileMemberName. Then it should write the String pContents
to the member just created. The length of pContents can be different for
different members in the same file. The class i wrote below throws a file
already exists exception when I call the methog writeFileOnAS400() for the
second time.
All help appreciated...Thanks
import com.ibm.as400.access.*;
public class AS400Utility
{
public static void writeFileOnAS400(String pFileName, String
pFileMemberName, String pContents ) throws Exception
{
AS400 as400 = new AS400();
String as400FileName = "/QSYS.LIB/IQFILES.LIB/" + pFileName + ".FILE";
String as400MemberName = pFileMemberName + ".MBR";
// Create a file object that represents the file
SequentialFile newFile = new SequentialFile(as400, as400FileName + "/" +
as400MemberName);
// Create the file
newFile.create(pContents.getBytes().length, "*DATA", "Data file created with
" + pContents.getBytes().length + "byte record." );
// Open the file for writing only.
// Note: The record format for the file
// has already been set by create()
newFile.open(AS400File.WRITE_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
// Write a record to the file. Because the record
// format was set on the create(), getRecordFormat()
// can be called to get a record properly formatted
// for this file.
Record writeRec = newFile.getRecordFormat().getNewRecord();
writeRec.setField(0, pContents);
newFile.write(writeRec);
// Close the file since I am done using it
newFile.close();
// Disconnect since I am done using
// record-level access
as400.disconnectService(AS400.RECORDACCESS);
}
public static void main(String args[])
{
System.out.println("Writing file to AS400...");
try
{
writeFileOnAS400("BPL0000004", "M001", "<SampleXML>The sample file
1</SampleXML>");
System.out.println("Finished writing file 1");
writeFileOnAS400("BPL0000004", "M002", "<SampleXML>The sample file 2 is
larger than sample file 1</SampleXML>");
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Completed file writing to AS400...");
}
}
_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.