简体   繁体   English

如何读取非常大的文件,即100MB作为字符串

[英]How to read very large file i.e 100MB as String

My large_file.txt contains <tag> to represent data such as parents, childs and so on. 我的large_file.txt包含<tag>来表示父母,孩子等数据。 My large_file.txt format is not xml format. 我的large_file.txt格式不是xml格式。

I want to read large_file.txt size 100 MB as a one string, then using String matching to get my data as a object. 我想将large_file.txt大小100 MB作为一个字符串读取,然后使用String匹配将我的数据作为对象。

Any help please? 有什么帮助吗?

Thanks in advance 提前致谢

I want to read large_file.txt size 100 MB as a one string 我想读取large_file.txt大小100 MB作为一个字符串

You really don't want to do that. 你真的不想那样做。 You want to do anything you can to avoid it. 你想做任何你能做的事情来避免它。 You should always aim to process files a piece at a time. 您应该始终瞄准一次处理文件。 What happens when the file gets 10 times the size? 当文件大小达到10倍时会发生什么? 100? 100? 1000? 1000?

You can use Jakarta Regexp 's StreamCharacterIterator . 您可以使用Jakarta RegexpStreamCharacterIterator This way you can directly apply string matching on the file without reading it first into a String object. 这样,您可以直接在文件上应用字符串匹配,而无需先将其读入String对象。

Otherwise you can use Commons IO's FileUtils . 否则,您可以使用Commons IO的FileUtils

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

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