简体   繁体   English

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

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

相关问题 在Java中逐行读取和写入大文件的最快方法 - Fastest Way To Read and Write Large Files Line By Line in Java 用Java读取大tiff图像的最快方法是什么? - What is the fastest way to read a large tiff image in java? 使用Java从文件读取和写入字符串的绝对最快方法是什么? - What is the absolute fastest way to read and write strings from a file with Java? 在 Java 中读取大型 XML 文件的最快方法 - Fastest way to read a large XML file in Java 检索大量DTO最快的Java集合是什么? - What is the fastest java collection for retrieving large numbers of DTOs? 将 memory 中的大量数据写入文件的最快方法是什么? - What is the fastest way to write a large amount of data from memory to a file? 将大量小文件读入内存的最快方法是什么? - What is the fastest way to read a large number of small files into memory? 从java中的大文件中读取和处理字符串的最快方法? - Fastest way to read and process string from large file in java? 什么是在java中扫描非常大的文件的最快方法? - what's the fastest way to scan a very large file in java? 在Java中用文件写一个非常小的字符串的最快方法是什么? - What's the fastest way to write a very small string to a file in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM