|
Inspired by Dave, I decided to add on to the work that he did. You can create the member in your program as well, as I do here using the exec method. Then I just wrote to it with Dave's code. Again, the data is still in unicode. Someone else can deal with that. :) -------------------------------- import java.io.*; public class CreateMember { public static void main(java.lang.String[] args) { CreateMember test = new CreateMember(); test.createIt(); test.writeToIt(); } public void createIt() { try { Runtime myRuntime = Runtime.getRuntime(); String dupString = "system 'ADDPFM FILE(CUJOLIB/QCSRC) MBR(NEWSRC)'"; Process myProcess = myRuntime.exec(dupString); checkForErrors(myProcess.getErrorStream()); } catch (Exception e) { System.out.println("Caught exception: " + e.getMessage()); e.printStackTrace(); } } protected void checkForErrors(InputStream i) throws Exception { InputStreamReader inStream; String stderrText; try { BufferedReader in = new BufferedReader(new InputStreamReader(i, "Cp037")); stderrText = in.readLine(); } catch (Exception e) { throw new Exception("Error accessing execution stream." + e); } if (stderrText != null) { // Ignore message for member created. Throw exception on all others. if (!stderrText.startsWith("CPC7305")) throw new Exception(stderrText); } } protected void writeToIt() { try { FileOutputStream f = new FileOutputStream("/QSYS.LIB/CUJOLIB.LIB/QCSRC.FILE/NEWSRC.MBR"); PrintWriter pw = new PrintWriter(f); pw.write("line 1"); pw.write("line 2"); pw.flush(); pw.close(); f.close(); } catch (Exception e) { System.out.println("Caught exception: " + e.getMessage()); e.printStackTrace(); } } } Regards, Richard D. Dettinger AS/400 Native JDBC Driver Team "I don't see much sense in that," said Rabbit. "No," said Pooh humbly, "there isn't. But there was going to be when I began it. It's just that something happened to it along the way." dawall@us.ibm.com on 08/23/99 03:43:09 PM Please respond to JAVA400-L@midrange.com To: JAVA400-L@midrange.com cc: Subject: Re: Java program write to /qsys.lib file system? I wrote a small testcase and found you can write to a member as long as the member exists before running the Java program. The source for my test is: FileOutputStream f = new FileOutputStream("/QSYS.LIB/DAW.LIB/DAW.FILE/A.MBR"); PrintWriter pw = new PrintWriter(f); pw.write("line 1"); pw.write("line 2"); pw.flush(); pw.close(); f.close(); If I first create the member data was written to the file. If I do not create the member, I get a FileNotFound exception. I will not speak for the value of the data, however. Since java.io classes write the data it ends up being unicode. If an AS/400 app is going to digest the data, I hope it can handle unicode. As mentioned in another append, the Toolbox has classes to write to the IFS and will convert the data. I re-wrote my test case to: AS400 system = new AS400(); IFSTextFileOutputStream f = new IFSTextFileOutputStream(system, "/QSYS.LIB/DAW.LIB/DAW.FILE/A.MBR", 37); f.write("line 1 \n"); f.write("line 2 \n"); f.flush(); f.close(); The data written to the file is EBCDIC so I am able to use AS/400 tools (like SEU) to edit the same file. Also, the Toolbox class creates the file if it doesn't exist so the file does not have to exist before the Java program runs. If you don't have access to the source then you can't change the app to use Toolbox classes but it is an option if you have access to the source. David Wall AS/400 Toolbox for Java Folks: Does anyone know if it's possible for a java program, running on the '400, to write to a source pf? The output file I want to write to is /QSYS.LIB/DEVDMGWRK.LIB/JAVAOUT.FILE/JAVAOUT.MBR The java program I'm running (and I admit, I don't know much about it currently) complains that it can't find the file. Thanks! david +--- | This is the JAVA/400 Mailing List! | To submit a new message, send your mail to JAVA400-L@midrange.com. | To subscribe to this list send email to JAVA400-L-SUB@midrange.com. | To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com. | Questions should be directed to the list owner: joe@zappie.net +--- +--- | This is the JAVA/400 Mailing List! | To submit a new message, send your mail to JAVA400-L@midrange.com. | To subscribe to this list send email to JAVA400-L-SUB@midrange.com. | To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com. | Questions should be directed to the list owner: joe@zappie.net +--- +--- | This is the JAVA/400 Mailing List! | To submit a new message, send your mail to JAVA400-L@midrange.com. | To subscribe to this list send email to JAVA400-L-SUB@midrange.com. | To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com. | Questions should be directed to the list owner: joe@zappie.net +---
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.