The flat file type (.flat) is used with ASCII files (.asc), which contain fixed-length fields and optional line ends to mark the end of records. The actual ASCII data does not contain any information about the structure of fields nor the data types of those fields. For information on data types, see Data Types.
Reading and writing flat files
Use an Input Data Tool and Output Data Tool to read and write .flat files. If you are reading an unknown file type into Designer and have selected the Read it as a fixed width text file option, see Flat File Layout.
Flat file structure
The .flat file is written in XML and can be modified to describe information about the structure and data types of fields. The root element is flatfile with a version attribute, which must be set to 1. The flatfile element contains the following child elements:
- file: Declares where the actual flat-ASCII data is located and what kind of properties it has. It has the following attributes:
- path: The path to the data file. It can be absolute or relative to the description file.
- eoltype: The kind of line ends that are used. Valid options are none, crlf (default, Windows), lf (Unix), cr (Mac).
- allowShortLines: Indicates if record can end before all fields are read. This is valid only for data with line ends. Missing fields will be set to "null". Valid options are true (t) or false (f) (default).
- allowLongLines: Indicates if there can be extra characters after the last field for the current record. This extra data will be discarded. Valid options are true (t) or false (f) (default).
- trimWhiteSpace: When this is true, blank characters are trimmed from field data. Valid options are: true (t) (default) or false (f).
- fields: Contains one or many field elements. It has the following attributes:
- type: The data type of field. Valid types for flat files are Bool, Byte, Int16, Int32, Int64,FixedDecimal, Float, Double, String, V_String.
Byte is an unsigned number between 0-255, so the size of byte is 3 characters. See Data Types for descriptions and examples of these types.
- name: The name of field.
- length: The length of field.
- scale: Only used if the field type is FixedDecimal, in which case this attribute is mandatory.
<flatfile version="1"> <file path="data.asc" eoltype="lf" trimWhiteSpace="f" allowShortLines="t" /> <fields> <field name="KEY " type="String" length="5" /> <field name="NAME" type="String" length="12" /> <field name="VALUE" type="Double" length="20" /> </fields> </flatfile>