如何将 .txt 文件转换为 .xls 文件 read/write?
How do I convert from .txt to .xls file read/write?
所以在我的项目中,我曾经使用 read/write 数据 from/to .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));}
现在我必须改变这个,我对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 )
试试这个,
Lists.partition(pv1Column, 3);
使用 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]
所以在我的项目中,我曾经使用 read/write 数据 from/to .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));}
现在我必须改变这个,我对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 )
试试这个,
Lists.partition(pv1Column, 3);
使用 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]