1

so I am currently working on a java project in intellij and in order to run the program that I have coded the java main has to access information from a csv file called "Surnames_2010Census.csv" . However, whenever I got to run the program it says that the file can not be found even though it is clearly there. My question is what do I have to do in order for intellij to find said file and run my code. Below I have posted the code for my main.java file.

package edu.cscc;

public class Main {
    private final static String CENSUSDATAFNAME = "Surnames_2010Census.csv";

    public static void main(String[] args) {

        Surname[] namelist = Census.loadCensusData(CENSUSDATAFNAME);

        if (namelist != null) {
            System.out.println("Rank\tName");
            for (Surname name : namelist) {
                System.out.println(name.getRank() + "\t\t" + name.getName());
            }
        }
    }
}
Stidgeon
  • 2,673
  • 8
  • 20
  • 28
NickV
  • 11
  • 1
  • You're not sharing the file hierarchy, nor the code loading the data, nor the exception with its stacktrace. Only an all-knowing god could answer the question in its current state. – Dici Apr 13 '20 at 15:16
  • It will need to be in your resources folder. Checkout this post https://stackoverflow.com/questions/15749192/how-do-i-load-a-file-from-resource-folder They have their resources under /src/main/resources/. Put your census file there and check the linked post above on how to read it in. Without more info, this is as much as I can help. – TJReinert Apr 13 '20 at 15:18
  • My project structure is as follows: – NickV Apr 13 '20 at 15:32
  • /src/main/java/ /src/Census/java/ /src/Surname/java/ Surnames_2010Census.csv – NickV Apr 13 '20 at 15:34
  • Seeing the same thing with ICIJ-Offshore-Leaks CSV-file – Zach May 23 '23 at 14:12

0 Answers0