繁体   English   中英

用Java编写/读取大表的最快方法是什么?

[英]What is the fastest way to write/read large table of numbers in Java?

我有两个数字数组的连接向量。 写/读它们的最快方法是什么? 我应该使用默认的(反)序列化还是其他某种技术? XML当然效率太低。

将它们写为二进制文件,其中前4个字节是数量的计数,其后每4个字节是一个数字。

更新:代码示例

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.

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