以下代码用于读取Java中现有的Excel文件。
我想使用[[a, b], [b, c, d], [a, c, d, e], [a, d, e], [a, b, c], [a, b, c, d], [a], [a, b, c], [a, b, d], [b, c, e]]...
,其中[a, b]
引用了Excel文件中的一行。请帮助我。
public class Excel {
public static void main(String[] args) throws FileNotFoundException {
List<Set<String>> itemsetList = new ArrayList<>();
Scanner scanner = new Scanner(new File("bc_dataset.csv"));
scanner.next();
while (scanner.hasNext()) {
String str = scanner.next();
itemsetList.add(new HashSet<>(Arrays.asList(str.split(","))));
System.out.println(itemsetList);
}
scanner.close();
}
}
答案 0 :(得分:0)
按如下所示更改代码:
public class Excel {
public static void main(String[] args) throws FileNotFoundException {
List<Set<String>> itemsetList = new ArrayList<>();
Scanner scanner = new Scanner(new File("bc_dataset.csv"));
while (scanner.hasNextLine()) {
String str = scanner.nextLine();
itemsetList.add(new HashSet<>(Arrays.asList(str.split(","))));
}
System.out.println(itemsetList);
scanner.close();
}
}