.txt 限制,需要帮助
我在这里遇到问题,不知道该怎么办。基本上我正在创建一个 .txt 文件,用作随机访问文件的索引。其中我有查找文件中每个条目所需的字节数。
该文件有 1484 条记录。这就是我遇到问题的地方:由于记录有大量字节,我最终在文件中写入了相当长的数字,最终 .txt 文件变得太大。当我使用适当的软件(例如记事本)打开它时,文件会在某个点被切断。
我试图尽可能地减少它,但它太大了。
我在这里能做什么?我一无所知。
谢谢。
I have a problem here and no idea what to do. Basically I'm creating a .txt file which serves as an index for a random access file. In it I have the number of bytes required to seek to each entry in the file.
The file has 1484 records. This is where I have my problem: with the large amount of bytes the record has, I end up writing pretty long numbers into the file, and ultimately the .txt file ends up being too big. When I open it with an appropriate piece of software (such as notepad) the file is simply cut off at a certain point.
I tried to minimize it as much as possible, but it's just too big.
What can I do here? I'm clueless.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不太确定问题是那个...只有 1484 条记录?
您可以改为编写一个二进制文件,其中每四个或八个字节对应一个记录位置。这样,所有位置在磁盘上都具有相同的长度,无论它们包含多少位数字。如果您需要浏览/修改文件,您可以轻松编写实用程序来解码文件,以便您检查它,并对您的修改进行编码并修改它。
另一种解决方案是压缩文件。您可以使用Java的zip功能,在使用文件之前解压缩文件,然后再次压缩它。
I am not really sure that the problem is that one... only 1484 records?
You can write a binary file instead, in which each four or eight bytes correspond to a record position. This way, all positions have the same length on disk, no matter how many digits they hold. If you need to browse/modify the file, you can easily write utility programs that decode the file so it lets you inspect it, and that encode your modifications, modifying it.
Another solution would be to compress the file. You can use the zip capabilities of Java, and unzip the file before using it, and zip it again after that.
这可能是因为您没有输入新行来终止每行。文本编辑器可以安全处理的最大行长度是有限制的。
It is probably because you are not feeding new lines to terminate each line. There is a limit set to the maximum line length that text editors can handle safely.
将索引存储在某种集合中的二进制文件中(取决于您的需要)可能会更快、更轻。
Storing your indices in a binary file, inside some kind of Collection (depending on your needs) would probably be much faster and lighter.