I have a .csv-File with twitter data. There are rows and columns.
My code to read it in is:
public static void main(String[] args) {
String csvFile = "twitter.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = ";";
try {
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
String twitter[] = line.split(cvsSplitBy);
System.out.println(twitter[2]);
}
}
Now when i use System.out.println(twitter[2]) he will print the third column:
My question: How can i access one specific field in my array. I don't want the whole column printed. I just want one number of the column.
for your while loop, change it to this:
int row_desired = 123;
int row_counter = 0;
while ((line = br.readLine()) != null) {
if (row_counter++ == row_desired) {
String twitter[] = line.split(cvsSplitBy);
System.out.println(twitter[2]);
}
}
note, that will leave out your column header, add a || row_counter == 1
|| row_counter == 1
clause to the if expression evaluation to show the header
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.