1

I am looking for effective way to split string/char from huge files line by line.

The split pattern is same for all line. Goal is to read line by line and parse the line then save in objects.

For ex, line in file is

This is a sample for line 1.
Here is a sample for line 2.next 

parsing is Save "1st character in an object 1, then next 3 character in object 2 etc.

My code is :

 try (Stream<String> stream = Files.lines(Paths.get((sampleFile)))) {
  stream.forEach(e -> parseFile(e));
  }

private static void parseFile(String line){
String object1= line.substring(0, 1);
String object2 = line.substring(1, 3);

// then saving this objects in a list and finally saving it in DB.
}

As the file is huge and line is of 1800 character. 15 Objects will be created from it and then above logic is executed.

Help i am looking for is on below question :

1) I am looking for some other way instead of substring.

2) There are 4 format file and each of them has separate parsing.

Alex Sveshnikov
  • 4,214
  • 1
  • 10
  • 26

0 Answers0