I have .txt file which I convert to string. I want to store every 2 new lines starting from the 1 all the way to the last number.
name.txt file:
imported/names/A
1/name=Arwin
2/Age=22
3/name=AJ
4/Age = 27
5/name=Anna
6/Age = 21
7/name=Avon
8/Age = 25
9/name=Atman
10/Age = 19
I want to store these contents in a array list seperating every 2 new lines:
ArrayList = ["1/name=Arwin2/Age=22","3/name=AJ4/Age = 27","5/name=Anna
6/Age = 21","7/name=Avon8/Age = 25"9/name=Atman10/Age = 19"]
So fair I have this code but the last line splitting doesnt really work because for this file I have to skip the very first line and then split the rest 2 lines at a time which makes it not work:
File file = new File(classLoader.getResource("name.txt").getFile());
String data = FileUtils.readFileToString(file, "UTF-8");
List<String> items = Arrays.asList(data.split("\\n\\n));