Java FileReader提供了一个找不到文件的错误

时间:2015-10-18 18:18:59

标签: java

这没有任何意义。我尝试指定相对和绝对路径。我打印出当前目录,然后检查以确保文件存在,我仍然收到此错误。该文件未在任何其他应用程序中打开。我尝试制作副本并将它们移动到其他目录。正斜杠,反斜杠,双斜线,我能想出的任何斜线,但错误仍然存​​在。

这是完整的代码:

package module2;
import java.io.*;
import java.util.*;
import com.opencsv.CSVReader;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.marker.Marker;
import de.fhpotsdam.unfolding.utils.MapUtils;
import processing.core.PApplet;


public class LifeExpectancy extends PApplet {
    UnfoldingMap map;
    Map<String, Float> lifeExpByCountry;
    List<Feature> countries;
    List<Marker> countryMarkers;

    public void setup() {
        String curDir = System.getProperty("user.dir");
        System.out.println(curDir);
        lifeExpByCountry = loadLEMapFromCSV("LifeExpectancyWorldBank.csv");
        countries = GeoJSONReader.loadData(this, "countries.geo.json");
        countryMarkers = MapUtils.createSimpleMarkers(countries);
        map.addMarkers(countryMarkers);
        shadeCountries();
    }

    public void draw() {

    }

    private Map<String, Float> loadLEMapFromCSV(String fileName) {
        Map<String, Float> lifeExpMap = new HashMap<String, Float>();
        CSVReader reader = new CSVReader(new FileReader(fileName));
        String[] line;
        while ((line = reader.readNext()) != null) {
            float value = Float.parseFloat(line[5]);
            lifeExpMap.put(line[4], value);
        }
        return lifeExpMap;
    }

    private void shadeCountries() {
        for (Marker m : countryMarkers) {
            String id = m.getId();

            if (lifeExpByCountry.containsKey(id)) {
                float lifeExp = lifeExpByCountry.get(id);
                int colorLevel = (int) map(lifeExp, 40, 90, 10, 255);
                m.setColor(color(255 - colorLevel, 100, colorLevel));
            }
            else {
                m.setColor(color(150, 150, 150));
            }
        }
    }

}

这是导致错误的特定行:

CSVReader reader = new CSVReader(new FileReader(fileName));

我使用Eclipse Mars IDE。

编辑:这是最低限度的代码:

package test;

import java.io.FileReader;

public class FileReaderTest {
    public static void main (String[] args) {
        FileReader reader = new FileReader("C:/Users/Denis/workspace/UCSDUnfoldingMaps/data/LifeExpectancyWorldBank.csv");
    }
}

0 个答案:

没有答案