使用StringTokenizer示例解析CSV文件
/** 来 自 时 代 J a v a - nowjava.com **/ import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { try { String strFile = "C:/Folder/example.csv";/**来 自 N o w J a v a . c o m**/ BufferedReader br = new BufferedReader( new FileReader(strFile)); String strLine = ""; StringTokenizer st = null; int lineNumber = 0, tokenNumber = 0; while( (strLine = br.readLine()) != null) { lineNumber++; //break comma separated line using "," st = new StringTokenizer(strLine, ","); while(st.hasMoreTokens()) { //display csv values tokenNumber++; System.out.println("Line # " + lineNumber + ", Token # " + tokenNumber + ", Token : "+ st.nextToken()); }