[VB.NET]大容量文件编码转换问题,高手请进,在线等

来源:互联网 发布:js实现圆形进度条 编辑:程序博客网 时间:2024/05/01 04:49
VB.NET源码-156个实用实例哦……<script type="text/javascript"><!--google_ad_client = "pub-8333940862668978";/* 728x90, 创建于 08-11-30 */google_ad_slot = "4485230109";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
大容量文件编码转换问题,高手请进,在线等
最近在做一个项目,需要把一个UTF-8编码的文件转换成GB2312编码的文件,由于文件太大,有200多M,转换的时候十分消耗内存,请大家看一下,有什么办法可以节约内存,谢谢。
代码如下

原先的代码,很耗内存。。。
My.Computer.FileSystem.WriteAllText(file2, My.Computer.FileSystem.ReadAllText(file1), False, System.Text.Encoding.GetEncoding( "GB2312 "))

现在的代码,也很耗内存。。。
byte1 = IO.File.ReadAllBytes(file1)
byte2 = Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding( "GB2312 "), byte1)
IO.File.WriteAllBytes(file2, byte2)
__________________________________________________________________________
你可以把这个文本分为N份,然后开N条线程转换,转换完后再合并
__________________________________________________________________________
试一下:
StreamReader sr = new StreamReader (file1, Encoding.UTF8);
StreamWriter sw = new StreamWriter (file2, Encoding.GetEncoding("GB2312"));
char[] buffer = new char[1024];
然后循环从sr中读取到Buffer中,再Write到sw,直到文件结束,后面的代码略(因为下班了:))
__________________________________________________________________________