简体   繁体   English

用Java读取文件并记住停止的字节

[英]Reading File in Java and memorize bytes where it stops

i've to read in a .txt file. 我必须读一个.txt文件。 That File contains 13 parameters seperated by ",". 该文件包含以“,”分隔的13个参数。 I read it line by line, split after "," and wrote those 13 parameters in a database. 我一行一行地读取它,在“之后”分割,然后将这13个参数写入数据库中。 But theres one Problem : 但是有一个问题:

That file gets a bit bigger everyday (~ 2mb), so reading it by line will soon take a lot of time. 该文件每天都会变大(〜2mb),因此按行读取该文件很快会花费很多时间。 So i thought of the following: 所以我想到了以下几点:

I want to read the file, then memorize the amount of bytes where the file finishes, write this "pointer" in a database and then next time start reading AFTER that bytes where the pointer is pointing to. 我想读取文件,然后记住文件结束处的字节数,在数据库中写入此“指针”,然后下一次在指针指向的字节之后开始读取。 (This way i don't have to read the whole stuff i already have again). (这样一来,我不必再次阅读已经拥有的全部内容)。

How can i do this? 我怎样才能做到这一点?

Thanks! 谢谢!

You can do this using Random Access File . 您可以使用随机访问文件来执行此操作。 It lets you access file randomly, and thereby, you can start reading the file, from wherever you need to(not necessarily from the start). 它使您可以随机访问文件,从而可以从所需的任何地方开始读取文件(不一定从头开始)。

根据这篇文章: http : BufferedReader具有一个skip()方法,该方法可用于跳入文件(似乎与随机访问文件类似)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM