如何从.txt转换为.xls文件读/写?

时间:2017-03-21 09:51:26

标签: java jxl

所以在我的项目中,我曾经从/ .txt文件读取/写入数据,但我意识到如果我从excel文件那样做会更好。这就是我做到的。

        for (File benchmarkLoop : listOfFiles) {
        String line = null;
        BufferedReader in = null;
        try {
                in = new BufferedReader(new FileReader("benchmarks\\" + benchmarkLoop.getName()));  
            } catch (FileNotFoundException fnfe) {
                fnfe.printStackTrace();
            }
            Writer writer = null;
            File file = new File("results", benchmarkLoop.getName());
            writer = new BufferedWriter(new FileWriter(file));}

现在我必须改变这一点,而且我对[{1}}不熟悉。

jxl

3 个答案:

答案 0 :(得分:2)

试试这个,

Lists.partition(pv1Column, 3);

参考:Lists.Partition()

答案 1 :(得分:0)

使用Java 8而不使用任何其他库:

private static <T> List<List<T>> partitionList(List<T> list, int size) {
    return IntStream.range(0, (list.size() + (size - 1)) / size)
            .mapToObj(x -> list.subList(x * size, Math.min((x + 1) * size, list.size())))
            .collect(Collectors.toList());
}

答案 2 :(得分:0)

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class SplitList {
    public static void main(String[] args){
        List<Integer> list = IntStream.rangeClosed(0, 10).boxed().collect(Collectors.toList());
        int[] count = new int[1];
        List<List<Integer>> sublists = list.stream()
                .collect(Collectors.groupingBy(e -> (list.size() - count[0]++)/6))
                .values()
                .stream()
                .collect(Collectors.toList());
        sublists.stream().forEach(System.out::println);
    }
}


>> The results on cli:
[6, 7, 8, 9, 10]
[0, 1, 2, 3, 4, 5]