从Java中的文件中读取大量BitSet对象

时间:2012-04-16 12:00:14

标签: java file-io bitset

我想从文件中读取大量BitSet个对象(12MB)。我使用下面的代码但只读取文件中的第一个对象并重复它。谢谢

public static void main(String[] args) {
    // TODO code application logic here

    ObjectInputStream Input = null;
    FileInputStream Database = null;
    Object Buffer = null;
    BitSet H = null;


    try
    {
        Database = new FileInputStream("BloomFilters.txt");
        Input = new ObjectInputStream(Database);

        while((Buffer =  Input.readObject()) != null)
        {
            H = (BitSet)Buffer;
            System.out.println(H);
            System.out.println("Yes" );
        }
    }
    catch(Exception e)
    {
        System.out.println("Exp = " + e.getMessage());
    }

以下代码创建一个BitSet对象文件,我想要从这个文件中读取对象

public class Main {

public static void main(String[] args) {
    BloomFilter Set = new BloomFilter(512, 100);
    ObjectOutputStream Output = null;
    DataInputStream Input = null;
    FileOutputStream DBOut = null;
    FileInputStream DBIn = null;
    String Sequence = "";


    try
    {
        DBOut = new FileOutputStream("Bloomfilters.txt");
        Output = new ObjectOutputStream(DBOut);
        DBIn = new FileInputStream("DB.txt");
        Input = new DataInputStream(DBIn);

        while((Sequence = (String) Input.readLine()) != null)
        {
            Set.clear();
            for(int i = 0; i < Sequence.length() - 1; i++)
                Set.add((Sequence.substring(i, i + 2)));
            BitSet buffer = Set.getBitSet();

            Output.writeObject(buffer);
        }

        Input.close();
        Output.close();
    }
    catch(Exception e)
    {
         System.out.println(e.getMessage());
    }
}
}

1 个答案:

答案 0 :(得分:0)

我认为您需要扫描程序才能看到此代码Java Bitset error with large index。这是一个不同的问题,但第一个循环是将一个带有数字的大文件读入一个位集,