【发布时间】:2023-04-03 00:38:01
【问题描述】:
我正在尝试编写一个 Java CSV 阅读器程序(使用我目前所学的知识,我是一个菜鸟)。但是,我现在不知道我的代码有什么问题。数据表很简单:
my,name,is,Tan
are,you,okay
i,am,okay,—
输出基本上没有显示任何内容。但是当我删除了破折号时,它起作用了。 以下是我的代码:
public static void main(String[] args) throws IOException{
Scanner read = new Scanner(new File("List3.csv"));
while(read.hasNext()){//if the txt file has next line then continue
String line = read.nextLine();
String[] lineArray = line.split(",");
//
for(int i = 0; i < lineArray.length; i++){
System.out.print(lineArray[i] + " ");
}
}
}
非常感谢。
【问题讨论】:
-
等等。什么错误?
-
有什么问题?
-
em-dash 可以在 CSV 中...它只是一个字符串。
-
可能是字符集问题。但如果没有错误,就无法分辨
-
Em Dash 是一个 Unicode 字符 (\u{2014})。使用:
Scanner reader = new Scanner(new FileInputStream("List3.csv"), "UTF-8");读取文件。