[英]What is the fastest way to write/read large table of numbers in Java?
I have two connected vectors of arrays of numbers. 我有两个数字数组的连接向量。 What is the fastest way to write/read them?
写/读它们的最快方法是什么? Should I use default (de)serialization or some other technique?
我应该使用默认的(反)序列化还是其他某种技术? XML is of course too unefficient.
XML当然效率太低。
Write them as a binary file where the first 4 bytes is a count of how many, and every 4 bytes after that is a number. 将它们写为二进制文件,其中前4个字节是数量的计数,其后每4个字节是一个数字。
UPDATE: code sample 更新:代码示例
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;
/**
* Write the numbers in binary.
*/
public class WriteBinary {
public static void main(String[] argv) throws IOException {
Vector<int> numbers = getVectorOfNumbers();
int size = numbers.size();
String FILENAME = "binary.dat";
DataOutputStream os = new DataOutputStream(new FileOutputStream(
FILENAME));
os.writeInt(size);
for(int n : numbers) {
os.writeInt(n);
}
os.close();
System.out.println("Wrote " + size + " numbers to file " + FILENAME);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.