gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:22:32 25 4
gpt4 key购买 nike

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

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

最佳答案

我认为您需要扫描仪,请参阅此代码 Java Bitset error with large index 。这是一个不同的问题,但第一个循环是将带有数字的大文件读取到位集中,

关于java - Java从文件中读取大量BitSet对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10173669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com