【发布时间】:2017-11-22 00:22:50
【问题描述】:
如何在java中将String中的ArrayList分配给File[]。我试过如下图
ArrayList<String> fileList;
File[] file;
for (int i = 0; i < fileList.size(); i++) {
file = new File (fileList.get(i));
}
但我得到 file 无法转换为 File[]。请纠正我。
【问题讨论】:
-
do
file[i] = new File (fileList.get(i));另外,先初始化数组 -
fileList.stream().map(File::new).toArray(File[]::new)。另外,不要使用FileAPI - 这太糟糕了。使用新的PathAPI...