Ссылка на quick start для OpenCSV
, возникла проблема с открытием файла, который отображается как присутствующий в ОС, и с использованием exists
для демонстрации.
Код:
package net.bounceme.dur.basexfromjaxb.csv;
import com.opencsv.CSVReaderHeaderAware;
import java.io.File;
import java.io.FileReader;
import java.net.URI;
import java.util.Map;
import java.util.logging.Logger;
public class ReaderForCVS {
private static final Logger LOG = Logger.getLogger(ReaderForCVS.class.getName());
public ReaderForCVS() {
}
public void unmarshal(URI inputURI) throws Exception {
LOG.info(inputURI.toString());
File encyptFile = new File(inputURI);
System.out.println(encyptFile.exists());
Map<String, String> values = new CSVReaderHeaderAware(new FileReader("file:/home/thufir/jaxb/input.csv")).readMap();
}
}
файл не найден:
thufir@dur:~/NetBeansProjects/BaseXFromJAXB$
thufir@dur:~/NetBeansProjects/BaseXFromJAXB$ gradle run
> Task :run FAILED
Jan 10, 2019 1:47:50 PM net.bounceme.dur.basexfromjaxb.csv.ReaderForCVS unmarshal
INFO: file:/home/thufir/jaxb/input.csv
true
Exception in thread "main" java.io.FileNotFoundException: file:/home/thufir/jaxb/input.csv (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at java.io.FileReader.<init>(FileReader.java:58)
at net.bounceme.dur.basexfromjaxb.csv.ReaderForCVS.unmarshal(ReaderForCVS.java:23)
at net.bounceme.dur.basexfromjaxb.App.marshalCSV(App.java:24)
at net.bounceme.dur.basexfromjaxb.App.main(App.java:16)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
3 actionable tasks: 2 executed, 1 up-to-date
thufir@dur:~/NetBeansProjects/BaseXFromJAXB$
благодаря:
https://stackoverflow.com/a/18552188/262852