reading from csv

can't figure out why I cant read from this csv and split the values
4 Replies
JavaBot
JavaBot15mo ago
This post has been reserved for your question.
Hey @Mike B! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Mike B
Mike BOP15mo ago
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.File;

//Criteria:
//If GPA is >= 3.5
//If languages = Java
public class tst {
private String last_name;
private String first_name;
private String phoneNumber;
private String email;
private String address;
private String zipcode;
private String reigon;
private String languages;
private double GPA;
private String major;
private String university;


public static void main(String[] args) throws FileNotFoundException {
File info = new File("/Users/michaelbalogun/Desktop/Lab11/src/main/java/applicant_data.csv");
Scanner file = new Scanner(info);
while (file.hasNextLine()){
String text ="";
String[] candidates = text.split(",");
System.out.println("Last Name: " + candidates[0]);


}

}

}
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.File;

//Criteria:
//If GPA is >= 3.5
//If languages = Java
public class tst {
private String last_name;
private String first_name;
private String phoneNumber;
private String email;
private String address;
private String zipcode;
private String reigon;
private String languages;
private double GPA;
private String major;
private String university;


public static void main(String[] args) throws FileNotFoundException {
File info = new File("/Users/michaelbalogun/Desktop/Lab11/src/main/java/applicant_data.csv");
Scanner file = new Scanner(info);
while (file.hasNextLine()){
String text ="";
String[] candidates = text.split(",");
System.out.println("Last Name: " + candidates[0]);


}

}

}
I'm trying to print candidates[0] and I get nothing this my error "Index 1 out of bounds for length 1 at tst.main(tst.java:31)"
Kyo-chan
Kyo-chan15mo ago
String text = ""; ????
JavaBot
JavaBot15mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?