1

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());
    }
}
}
4

1 回答 1

0

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

于 2013-07-08T06:23:58.173 回答