Menu

Example of using FixedLengthWriter?

Help
2008-02-13
2013-04-22
  • Nobody/Anonymous

    Hello!

    Could anyone explain me a simple way to create a fixed lenght file? I want to query a DB and then put the results in fixed lenght file... i guess flatpack brings me FixedLenghtWriter.

    thanks a lot!
    Mario.

     
    • Eric Leray

      Eric Leray - 2008-02-14

      here is a trivial extract based on the PEOPLE xml mapping

      FixedWriterFactory factory = new FixedWriterFactory(mapping));
      Writer writer = factory.createWriter(new FileWriter(newFile));
      writer.addRecordEntry("LASTNAME", "DOE");
      writer.addRecordEntry("ADDRESS", "1234 CIRCLE CT");
      writer.addRecordEntry("STATE", "OH");
      writer.addRecordEntry("ZIP", "44035");
      writer.addRecordEntry("FIRSTNAME", "JOHN");
      writer.addRecordEntry("CITY", "ELYRIA");
      writer.nextRecord();
      writer.flush();

      E.

       
    • Nobody/Anonymous

      Thanks Eric.

       
  • mariomoya

    mariomoya - 2010-12-10

    Hello,
    Following this trivial example… Do you know how can I get a Map from the PEOPLE xml mapping? This map will be used to create FixedWriterFactory factory = new FixedWriterFactory(mapping));

    I'm think that the following is an aproach… but i'm not sure about the second argument of the FixedLengthParser constructor:

    {
           FileReader fr = null;
           final File xmlFile = new File(mapping);
           fr = new FileReader(xmlFile);       
           FixedLengthParser flp = new FixedLengthParser(fr, new FileReader(data));
           Map<String,String> mp = MapParser.parse(fr,flp);
           System.out.println(mp.toString());
    }
    
     

Log in to post a comment.