在VB.Net中读取一个大的.txt文件 [英] Read a large .txt file in VB.Net

查看:91
本文介绍了在VB.Net中读取一个大的.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要读取.txt文件,其中我的ID号为1320905829是关键,它有相关的记录。就像我有一个大的txt文件,它是26MB和

,其中有近226000条记录。为了避免任何内存泄漏,在VB.net中处理大型.txt文件的最佳方法是什么。是否有任何示例代码可以处理这个或任何建议。

随着文件的增长,处理这种情况的最佳方法是什么。有时文件也可能超过26MB。这取决于。主要原因是稍后将此文件的值与另一个.xls文件进行比较。

Hi,
I need to read .txt file where I have id number like 1320905829 is the key and it has related records to this key. Like that I have a big txt file which is 26MB and
almost 226000 records in it. To avoid any memory leaks what is the best way to handle reading a large .txt file in VB.net. Does any one has any sample code to deal
this or any suggestions.
As the file grows what is the best way to handle this situation. some times the file can be more than 26MB too. It depends. The main reason is to compare the values of this file to a different .xls file later on.

推荐答案

查看此链接



File.ReadLines Method(String) [ ^ ]



那里的重要注意事项:

See this link

File.ReadLines Method (String)[^]

The important note there:
Quote:

ReadLines ReadAllLines 方法的不同之处如下:当您使用 ReadLines 时,您可以开始枚举字符串集合整个系列归还;当您使用 ReadAllLines 时,必须等待返回整个字符串数组才能访问该数组。因此,当您使用非常大的文件时, ReadLines 可以更有效。

The ReadLines and ReadAllLines methods differ as follows: When you use ReadLines, you can start enumerating the collection of strings before the whole collection is returned; when you use ReadAllLines, you must wait for the whole array of strings be returned before you can access the array. Therefore, when you are working with very large files, ReadLines can be more efficient.



另请参阅此链接



如何:从文件中读取文本 [ ^ ]



问候..:)


Also refer this link

How to: Read Text from a File[^]

Regards..:)


听起来很糟糕。您应该考虑将文件加载到数据库中,然后在那里进行处理。

如果您不能这样做,那么更多信息会有所帮助。



0)每条记录是文件的一行吗?

1)ID是否按顺序排序(已排序)?

2)文件更改的频率?





为避免任何内存泄漏......



使用VB.net时,您可能不必担心内存泄漏,但内存使用可能是一个大文件的问题。





稍后将此文件的值与另一个.xls文件进行比较



啊,这完全是另一回事;你应该考虑阅读文本文件,然后在Excel文件中寻找ID,而不是相反。
Sounds like a bad situation. You should consider loading the file into a database and then working on it there.
If you can't do that, then more information would help.

0) Is each record one line of the file?
1) Are the IDs in order (sorted)?
2) How often does the file change?


"To avoid any memory leaks..."

When using VB.net, you probably needn't worry about memory leaks, but memory usage could be a concern with a large file.


"compare the values of this file to a different .xls file later on"

Ah, that's a different matter entirely; you should consider reading the text file and then seeking the IDs in the Excel file instead of the other way around.


这篇关于在VB.Net中读取一个大的.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆