|
Hii jatin & all, I want to write a java class "to write a file from outside AS/400 to AS/400" . I tried below code of jatin, but java.net.connect exception @1446 error coming i.e. AS/400 machine is not Responding to connection request.. Please help me out .. Regards vivek From: "Lateen 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..."); } } ************************************************************************** This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated. **************************************************************************
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.