[英]Array Index Out of Bound in java
package com.testing;
import java.io.BufferedReader;
import java.io.FileReader;
public class CsvParser {
public static void main(String[] args) {
String csvFile = "D:/code-home/SentimentAnalysis/test_data/Sentiment Analysis Dataset.csv";
BufferedReader br = null;
String line = "";
String cvsSplitBy = "\t";
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
// use comma as separator
String []tweet = line.split(cvsSplitBy);
System.out.println(tweet[1]);
System.out.println(tweet[3]);
}
}
The program's purpose is to parse the CSV format. 该程序的目的是解析CSV格式。 I have used bufferRead method.
我使用过bufferRead方法。
When I go to compile the program, it works fine. 当我去编译程序时,它可以正常工作。 When I run the program, I get an error,
当我运行程序时,出现错误,
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at com.testing.CsvParser.main(CsvParser.java:34)
You should use a comma separator. 您应该使用逗号分隔符。
Change 更改
String cvsSplitBy = "\t";
to 至
String cvsSplitBy = ",";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.