So, I'm using OpenCSV for a project I'm working on, and I've been doing fine so far, I managed to read a CSV file, as well as write to one. Because it's my first time using OpenCSV, I decided to use a tutorial I found on the internet, and adapt it a bit. So, what I've done is made a method called ReadData(). I can read the CSV and print it to the console fine, but what I want to do is access the "nextLine" array outside of the method.
public void ReadData(String filelocation) {
filelocation = System.getProperty("user.dir")+"/data/"+filelocation;
try {
CSVReader savereader = new CSVReader(new FileReader(filelocation), ',', '"', 0);
String[] nextLine;
while((nextLine = savereader.readNext()) != null) {
if(nextLine != null) {
//Make sure everything went through
System.out.println("Data Read. Results:");
System.out.println(Arrays.toString(nextLine));
}
}
} catch (FileNotFoundException ex) {
//Handle Exception
} catch (IOException ex) {
//Handle Exception
}
}
This method reads the data from a file I specify. But, I want to be able to do things with that data. For example, I would want to take nextLine[0], and see if it is empty, if it is, do one thing. If it's not, then I want to do something else that would make it equal something.
Thanks in advance, and I hope I was clear enough about what I'm trying to accomplish!
Regards,
Johnny