Open the file and read line by line. Then you can split the line at a specific character, in your example at a whitespace.
And since you want to access the data at a later point you can put the String Arrays from your split into a list.
public static void main(String[] args) {
File csvFile = new File("path/to/file");
List<String[]> results = new ArrayList<>();
try(BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
String line;
while((line = reader.readLine()) != null) {
results.add(line.split(" "));
}
} catch (IOException e) {
}
}
To make it a little bit more convenient you should use a POJO (Plain-Old-Java-Object)
public class CsvEntry {
private String parameterName;
private String parameterValue;
public CsvEntry(String parameterName, String parameterValue) {
this.parameterName = parameterName;
this.parameterValue = parameterValue;
}
}
public static void main(String[] args) {
File csvFile = new File("path/to/file");
List<CsvEntry> results = new ArrayList<>();
try(BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
String line;
while((line = reader.readLine()) != null) {
String[] split = line.split(" ");
results.add(new CsvEntry(split[0], split[1]));
}
} catch (IOException e) {
}
}
If you want to use the Java 8 way, this would be an example.
public static void main(String[] args) {
List<CsvEntry> results = new ArrayList<>();
try {
results = Files.lines(Path.of("path/to/file"))
.map(line -> line.split(" "))
.map(split -> new CsvEntry(split[0], split[1]))
.collect(Collectors.toList());
} catch (IOException e) {
}
}
To use your transformed data, access the entry via index:
results.get(700)