有几种方式来实现你想要做什么,
1)使用现有的库,它支持解析CSV的像拉维Thapliyal和Oibaf它建议。
2)你可以提供你的方法
a). if every line in your CSV have a uniform format like :
line 1 : 123,student,"exam notif","word , word , word"
line 2 : 45345,not student,"no exam notif","word,word,word"
you can say like
while(scan.hasNextLine()){
String line = scan.nextLine();
//split it using double quotes first
temp = line.split("\"");
//then just remove commas outside the double quoted objects
for(int x = 0; x
if(temp[x].startsWith(",")) {temp[x] = temp[x].substring(1,temp[x].length()); }
if(temp[x].endsWith(",")) {temp[x] = temp[x].substring(0,temp[x].length()-1); }
}
至于这个程序员而言,Java没有任何现有的类,方法多的分隔符,但也有一些图书馆,可以使生活更轻松为你 ,但你总是有一个选择,提供自己的方法。 GUD运气