Reputation: 227
I am trying to open a .csv file using FileReader in Eclipse. I have tried specifying the file's absolute path (as shown below), as well as moving the file into the current directory. Either way, I get the same I/O Exception - shown below after the code. Any help with this would be appreciated. thx
package demos;
import java.util.*;
import java.io.*;
import au.com.bytecode.opencsv.CSV;
import au.com.bytecode.opencsv.CSVReadProc;
import au.com.bytecode.opencsv.CSVWriteProc;
import au.com.bytecode.opencsv.CSVWriter;
import au.com.bytecode.opencsv.CSVReader;
public class ExampleCSVWrite {
public static void main (String[] args) {
CSVReader reader = new CSVReader(new FileReader("/Users/aaronarpi/Documents/UA.csv"));
List<String[]> myEntries = reader.readAll();
reader.close();
}
}
The exceptions are:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Unhandled exception type FileNotFoundException
Unhandled exception type IOException
Unhandled exception type IOException
at demos.ExampleCSVWrite.main(ExampleCSVWrite.java:12)
Upvotes: 0
Views: 924
Reputation: 15244
Error mentions about the uncatched IOException. You either need to throw or catch the IOException
public class ExampleCSVWrite {
public static void main (String[] args) throws IOException {
CSVReader reader = new CSVReader(new FileReader("/Users/aaronarpi/Documents/UA.csv"));
List<String[]> myEntries = reader.readAll();
reader.close();
}
}
Upvotes: 4