-1

I'm trying to do an assignment where we take data from a csv file and store it in arrays. Although I'm confident in being able to parse the lines and scan them into arrays, I cannot for the life of me figure out how to get the program to connect to the file. My professor wrote down something like

private String filename = "censusData";
private File file = new File(censusdata.csv);

But every time I try and use that, it says there's a symbol error and it can't find a variable censusdata. I'm using BlueJ. Is there some way I can add the file itself to my project and then access it? I just need the program to be able and read the file line by line so I can put the data into variables.

Claudia
  • 1
  • 1
  • 4
    File name needs to be in quotes: `new File("censusdata.csv")`. Or if you want to use your `filename` variable: `new File(filename + ".csv")` – shmosel Feb 16 '17 at 20:49
  • `private String filename = "censusData.csv"` and `private File file = new File(filename)` – Kevin Feb 16 '17 at 20:50
  • You'll want to give the full path of the file when you actually run that code. – OneCricketeer Feb 16 '17 at 20:54

1 Answers1

0

Try the following and see if it helps with your situation.
1) Make sure your .csv file is located in the same directory as your runnable java file. If you prefer a separate strategy you want to place the whole directory for the file location.
2) private String filename = "(optional path)/censusData.csv";
private File file = new File(filename);

ElementCR
  • 178
  • 12