[英]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 )
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.