[Solved] How can I read this unstructured flat file in Java?

Consider this file divided in middle present two record in same format, you need to design class that contains fields that you want to get from this file. After that you need to read

 List<String> fileLines  =  Files.readAllLines(Path pathToYourFile, Charset cs);

and parse this file with help of regular expressions. To simplify this task you may read lines and after that specify regexp per line.

class UnstructuredFile {
    private List<String> rawLines;

    public UnstructuredFile (List<String> rawLines) {
        this.rawLines = rawLines;

    public List<FileRecord> readAllRecords() {
        //determine where start and stop one record in list list.sublist(0,5) or split it to List<List<String>>


    private FileRecord readOneRecord(List<String> record) {
        //read one record from list


in this class we first detect start and end of every record and after that pass it to method that parse one FileRecord from List

Maybe you need to decouple you task even more, consider you have one record

data 1
data 2
data 3

we make to do classes RecordRowOne, RecordRowTwo etc. every class have regex that know how
to parse particular line of row of the record string and returns partucular results like

RecordRowOne {
    public RecordRowOne(String regex, String dataToParse) {

    int getDataOne() {

another row class in example has methods like


after you create all this row classes pass them to FileRecord class
that get data from all Row classes and it will be present one record of you file;

class FileRecord {

    public FileRecord(RecordRowOne one, RecordRowTwo two) {
        //get all data from rows and set it to fields

    //all getters for fields

it is basic idea for you

solved How can I read this unstructured flat file in Java?