I am doing an assignment for class where I have to open a text file and convert that said file into a 2d array so I can later access it depending on what the user requests.
So far, my code is this:
public static void main(String[] args) throws FileNotFoundException {
//create a scanner with the file as input
Scanner in = new Scanner(new File("src/EnglishResults06-12Citywide.csv"));
//check to see if there's a line available in the file
while(in.hasNextLine()){
//get the next line
String line = in.nextLine();
}
//close scanner
in.close();
//turns file into multi-dimensional array
String[][] grades = new String[98][15];
for (int i=0; i<results.length; i++) { //loop through each row
for (int j=0; j<results[i].length; j++) { //loop through all columns within the current row
results[i][j] = request //not sure how to assign the imported csv to the variable request
}
}
System.out.printf("Grade", "Year" , "Demographic" , "Number Tested" , "Mean Scale Score" , "Num Level 1" , "Pct Level 1" , "Num Level 2" , "Pct Level 2" , "Num Level 3" , "Pct Level 3" , "Num Level 4" , "Pct Level 4" , "Num Level 3 and 4" , "Pct Level 3 and 4");
I've imported the following:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
My text file has 98 rows and 15 columns. Here is the file: http://txt.do/xjar
I hope someone can help. Thank you so much in advanced!!!
String.splitis your friend, use it. The file format you are referring to is called CSV (comma-separated values), consider adding it as a tag.RegExpattern, so splitting by . will split by any character, if you are unsure, you can escape the argument withPattern.quote(...)