来自新CSVReaderHeaderAware的FileNotFoundException

时间:2019-01-10 21:27:37

标签: java file csv filenotfoundexception opencsv

参考OpenCSV的{​​{3}}开头,无法打开通过OS显示并通过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$ 

感谢:

quick

1 个答案:

答案 0 :(得分:0)

为什么不知道为什么?

public void unmarshal(URI inputURI) throws Exception {
    FileReader f = new FileReader(new File(inputURI));
    Map<String, String> values = new CSVReaderHeaderAware(f).readMap();
}