× 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.










From: "Jateen Patel" <patel_jateen@xxxxxxxxxxx>
Reply-To: Java Programming on and around the iSeries / AS400<java400-l@xxxxxxxxxxxx>
To: java400-l@xxxxxxxxxxxx
Subject: Help Writing File and Members to AS/400
Date: Fri, 28 Mar 2003 11:30:29 -0800


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


_______________________________________________
This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.




_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. http://join.msn.com/?page=features/virus



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.