Providing algorithm for this:
- Read each line of your file.
- For each line read:
- Split it by the separator (not sure if spaces or tab
\t
character, it depends on your file content). - Retrieve the 5th element.
- Store it in a collection, usually a
List<String>
.
- Split it by the separator (not sure if spaces or tab
You can easily accomplish this using Scanner
class:
List<String> desiredContent = new ArrayList<>();
Scanner scanner = new Scanner(new File("/path/to/file.csv"));
while (scanner.hasNext()) {
String line = scanner.nextLine();
String[] contents = line.split(" ");
desiredContent.add(contents[4]);
}