[英]Java Stream to String[] Array
I'm reading from a CSV file with a structure like this:我正在读取具有如下结构的 CSV 文件:
1;Miller Hame; 1,2,3,4,5.....; 1232323;
I have to split it to String[]
, I could work with every line and there with every "Part"
我必须将它拆分为
String[]
,我可以处理每一行以及每个"Part"
My Code so far:到目前为止我的代码:
Stream<String> input = java.nio.file.Files.lines(java.nio.file.Paths.get("data.csv"));
String[] lines = input.skip(1)
.map(s->s.split(";"))
.toArray(String[]::new);
Actually I'm getting java.lang.ArrayStoreException
.实际上我得到了
java.lang.ArrayStoreException
。
(Yes, it's for homework, but I don't want the whole solution, only for this very small part of the work.) (是的,它是为了作业,但我不想要整个解决方案,只针对作业中的这一极小部分。)
Something like this像这样的东西
Stream<String> input = Files.lines(Paths.get("src/data.csv"));
String[][] lines = input.skip(1)
.map(s -> s.split(";"))
.toArray(String[][]::new);
Advice: You don't have to type full path for a class.建议:您不必为类键入完整路径。 You can import it.
你可以导入它。 This is for
Files
and Paths
classes这是用于
Files
和Paths
类
import java.nio.file.Files;
import java.nio.file.Paths;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.