简体   繁体   English

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

[英]How do I convert from .txt to .xls file read/write?

So in my project I used to read/write data from/to .txt files, but I realized that It will be better if I would do that from an excel file. 因此,在我的项目中,我曾经从.txt文件中读取数据/向其中写入数据,但我意识到,如果我从excel文件中读取数据会更好。 This is how I did it. 这就是我做的。

        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));}

Now I have to change this and I'm not so familiar with jxl . 现在,我必须对此进行更改,并且我对jxl不太熟悉。

        while (initializingIterations > 0) {
                line = in.readLine();
                writer.write(0 + System.getProperty("line.separator"));          
                markov.update(  new Integer((int) (Math.round(Float.parseFloat(line)/interval))));   
                initializingIterations--;     
            }

        while ((line = in.readLine()) != null ) 

Try this, 尝试这个,

Lists.partition(pv1Column, 3);

Refer: Lists.Partition() 请参阅: Lists.Partition()

Using Java 8 without any additional libraries: 使用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());
}
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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM