The goal of my code is to ask for a user input, the user specifies this input and my code is to search and find out which row the user input is located.
Once located, I will then have code to extract that row into something (string array?) so I can then edit part of it's contents.
My problem is that I'm not sure which code/methods/classes to use in order to do this.
I have my code set up right now so that it reads the .CSV file and outputs it into a String array of type list. I then iterate through the array and find out if the user input that was specified is located within the file.
At the moment, my code only says if it is found, but I am unsure as to how to extract that specific row, and I was hoping you guys could help me out.
Here's my code at the click of a button:
try{
String strSearch = searchSerialField.getText();
CSVReader reader = new CSVReader(new FileReader("test.txt"), ',');
List<String[]> myEntries = reader.readAll();
reader.close();
//Write to existing file
//CSVWriter writer = new CSVWriter(new FileWriter("test.txt"), ',',CSVWriter.NO_QUOTE_CHARACTER, "\r\n");
//Iterate through my array to find the row the user input is located on
for (String[] line : myEntries)
{
ArrayList<String> newLine = new ArrayList<String>();
for (String word : line)
{
if (word.contains(strSearch))
{
//Need a method so I can find out what row my item is on
System.out.println("Found - Your item is on row: ...");
//Code to extract row into something (String array?) so I can edit it's contents
//I then need to write the edited row back to it's original row
}else
{
System.out.println("Not found");
}
}
}
}catch (IOException e)
{
System.out.println(e);
}
I've tried my best but I'm now stumped as to how I'm meant to extract the row, how can I go about doing this?
Thanks for the help.