Tag: 流读取器

如何读取字节和字符串的混合文件

我有一个带有大量字符串行和部分字节编码数据的混合文件。 例: –Begin Attach Content-Info: /Format=TIF Content-Description: 30085949.tif (TIF File) Content-Transfer-Encoding: binary; Length=220096 II*II* Îh ÿÿÿÿÿÿü³küìpsMg›Êq™Æ™Ôd™‡–h7ÃAøAú áùõ=6?Eã½/ô|û ƒú7z:>„Çÿý<þ¯úýúßj?å¿þÇéöûþ“«ÿ¾ÁøKøÈ%ŠdOÿÞÈGÈù#ä|’ò:#ä|Š”:#¢:;ˆèŽˆèʤV’ÑÑÑÑÑÑÑÑÑçIþ×o(¿zHDDDDDFp’.Ñ:ˆR:aAràÁ¬LˆÈù!ÿÿï[ÿ¯Äàiƒ”VƒDÇ)Ê6PáÈê$9C”9C†‡CD¡pE@¦œÖ{i~Úý¯kköDœ4ÉU”8`ƒt!l2G –End Attach– 我尝试用streamreader读取文件: string[] lines = System.IO.File.ReadAllLines(@”C:\Users\Davide\Desktop\20041230000D.xmm”) 我逐行读取文件,当行等于“Content-Transfer-Encoding:binary; Length = 220096”时,我读取所有后续行并写入“文件名”(在本例中为30085949.tif)文件。 但我正在读字符串,而不是字节数据和结果文件已损坏(现在我尝试使用tiff文件)。 对我有什么建议吗? 解决方案感谢您的回复 我采用了这个解决方案:我构建了一个LineReader扩展BinaryReader: public class LineReader : BinaryReader { public LineReader(Stream stream, Encoding encoding) : base(stream, encoding) { } public int currentPos; private StringBuilder stringBuffer; […]

阅读非常大的文本文件,我应该合并异步吗?

我一直面临着制作一种方法的挑战,该方法将非常大的文本文件读入程序,这些文件的范围可以从2gb到100gb。 到目前为止,这个想法一直是读取方法中的几千行文本。 目前,使用流阅读器设置程序,逐行读取文件并处理在该行上找到的必要数据区域。 using (StreamReader reader = new StreamReader(“FileName”)) { string nextline = reader.ReadLine(); string textline = null; while (nextline != null) { textline = nextline; Row rw = new Row(); var property = from matchID in xmldata from matching in matchID.MyProperty where matchID.ID == textline.Substring(0, 3).TrimEnd() select matching; string IDD = textline.Substring(0, 3).TrimEnd(); foreach […]

C#Stream.Read超时

我有这个streamreader: Boolean read = false; while (wline!=”exit”) { while (!read || streamReader.Peek() >= 0) { read = true; Console.Write((char)streamReader.Read()); } wline = Console.ReadLine(); streamWriter.Write(wline+”\r\n”); streamWriter.Flush(); } 如何设置Read()方法的超时? 谢谢