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


  • Subject: Re: Dealing with AS/400 text file io
  • From: "Dave Wall" <dawall@xxxxxxxxxx>
  • Date: Wed, 9 May 2001 16:01:18 -0500
  • Importance: Normal

I spoke too soon.  Jeff found a way to use ReadLine with
IFSTextFileInputStream....

David Wall
AS/400 Toolbox for Java

---------------------------------------------------------------------------------------------------------------------------------------


Dave,
Here's how a person could do readLine() against an IFS text file, using
existing Toolbox classes and methods.  Though it's not an obvious solution,
it works fine.  After discussing with Chris, I think the most attractive
solution for now is to advertise this technique (in the javadoc,
Programmer's Guide, etc), and not add any new classes or methods.

- Jeff


    AS400 as400 = new AS400(args[0], args[1], args[2]);  // Grab first 3
args: sysname, uid, pwd
    String filePath = "/File1";
    int fileCcsid = Integer.parseInt(args[3]);    // Grab fourth arg: file
data CCSID.

    // Write Strings to the IFS file.
    IFSTextFileOutputStream outStream = new IFSTextFileOutputStream(as400,
filePath, fileCcsid);
    ConvTableWriter convWriter = new ConvTableWriter(outStream, fileCcsid);

    // Note: There's no need to construct a BufferedWriter over convWriter,
    // since ConvTableWriter already does its own buffering.
    System.out.println("Writing to file...");
    for (int i=0; i<10; i++) {
      convWriter.write("This is line " + i + "\n");
    }
    convWriter.close();

    // Read lines as Strings from the IFS file.
    IFSTextFileInputStream inStream = new IFSTextFileInputStream(as400,
filePath);
    ConvTableReader convReader = new ConvTableReader(inStream, fileCcsid);

    // Note: ConvTableReader does its own internal buffering, but to get a
readLine()
    // method, we need a BufferedReader.
    BufferedReader bReader = new BufferedReader(convReader);
    System.out.println("\nReading from file...");
    String line = bReader.readLine();
    while (line != null) {
      System.out.println(line);
      line = bReader.readLine();
    }
    bReader.close();



------------------------------------------------------------------------------------------------------




It is a text file on IFS.  I tried to use IFSFile,IFSFileInputStream,
IFSFileOutputStream, etc. but there isn't a readLine() method in these
classes.  I want to be able to read one line at a time.  With IFS file
access classes above, you can only read for a specific amount of byte at a
time not per line basis.


Marady Prak - Technical Support Specialist
300 Phillipi Road
P.O. Box 28512
Columbus, OH 43228
Phone: 614-278-7186
Fax: 614-278-4769
Email: mprak@biglots.com
Pager: 877-282-3426 PIN 6143956967




+---
| 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 thread ...


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.