下面的代码正在读取一个 .csv 文件并以(当前输出)方式在控制台上显示它。
我希望它在控制台上显示为(想要的输出)方式...对不起,我无法添加图像... (行)表示在 2 个数据之间,我需要一条垂直线...请指导我.谢谢你提前
想要的输出:-
Firstname (line) Lastname (line) Main-Email (line) (current employer) (line)
ram (line) rfa (line) k@.com (line) (golhys) (line)
电流输出:-
Line # 1 Token : "First Name","Last Name","Main-Email","Current Employer","Internal Contact ID","PSI Club Member Nbr.","Membership Type","Membership Status","Member Since","Membership Card Sent","Membership Start Date","Membership Expiration Date","Nationality 1","Membership ID"
读取文件.java
public static void main(String[] args) {
String fileName="C:/Users/Desktop/cvsFile.csv";
try {
BufferedReader br = new BufferedReader( new FileReader(fileName));
// String strLine = null;
StringTokenizer st = null;
int lineNumber = 0, tokenNumber = 0;
while( (fileName = br.readLine()) != null)
{
lineNumber++;
//break comma separated line using ","
st = new StringTokenizer(fileName, "");
while(st.hasMoreTokens())
{
//display csv values
tokenNumber++;
System.out.println("Line # " + lineNumber + " Token : "+ st.nextToken());//.replaceAll(",", ",|,") replaceAll("..(?!$)", "$0 ")
}
//reset token number
tokenNumber = 0;
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}