FileNotFoundException from new CSVReaderHeaderAware



引用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

为什么这有效我不知道:

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

相关内容

  • 没有找到相关文章

最新更新