CobolBuilder writing records to single line
Read Cobol data files in Java
Status: Beta
Brought to you by:
bruce_a_martin
Hi,
I am using jrecord to write records to file. But i writer is writing all records to a single. Can you please
check if below code is correct.
final ICobolIOBuilder ioBuilder = JRecordInterface1.COBOL.newIOBuilder(
"copybook").setFont("CP1252");
AbstractLineWriter writer = ioBuilder.newWriter("output.txt");
AbstractLine outline = null;
while(resultSet.next()){
outline = ioBuilder.newLine();
outline.getField("id").set(resultSet.getInt("id")));
writer.write(outline);
}
writer.close();
Excpected Output:
1234
5677
Receiving o/p:
12345677
Can you please update how i write individual record into multiple lines
Thanks
babu
Anonymous
Diff:
Diff:
Diff:
Diff:
What you need to do is set the setFileOrganization(Constants.IO_BIN_TEXT):
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
Thank you!Bruce .It is working perfectly now. Can you update how Constants.Io_BIN_TEXT helped here?
JRecord is designed to work with Cobol data structures. The setFileOrganization
tells JRecords are to be organised - i.e. what the line seperator is.
Fixed width Records
With length records, each record is a fixed length. There is no /r / n etc between individual records.
This is what was being used initially. JRecord provides 2 versions of fixed length records
does byte (stream based IO). You can use it for single byte charactersets / binary files.
Used for multi-byte character-sets (e.g.UTF-8, UTF-16)
VB Records
With Variable length records you have
JRecord provides several VB formats Constants.IO_VB, Constants.IO_VB_DUMP, Constants.IO_VB_FUJITSU, Constants.IO_VB_GNU_COBOL
Text files
For standard text files you can use
or
With Constants.IO_BIN_TEXT all IO is done at byte (stream level).
With Constants.IO_UNICODE_TEXT standard Java Read / writers are used
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
Thank you! Bruce for the detailed explanation.