streamreader

Modify FileStream

浪子不回头ぞ 提交于 2021-02-09 11:58:47
问题 I'm working now on a class that will allow editing very big text files (4Gb+). Well it may sound a little stupid but I do not understand how I can modify text in a stream. Here is my code: public long Replace(String text1, String text2) { long replaceCount = 0; currentFileStream = File.Open(CurrentFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None); using (BufferedStream bs = new BufferedStream(currentFileStream)) using (StreamReader sr = new StreamReader(bs)) { string line; while

Loading data into a 2D array from text file?

偶尔善良 提交于 2021-02-08 11:13:00
问题 I am using C# in a console application. I need to load data from a text file and load it into a 2d array. This is what I tried, but when I try to print out the contents of what gets returned nothing gets printed. public static int[,] LoadMap() { const string path = @"1.txt"; string[] fileLines = File.ReadAllLines(path); int[,] map = new int[fileLines.Length, 15]; string line; for (int i = 0; i < fileLines.Length; ++i) { line = fileLines[i]; for (int j = 0; j < line.Length; ++j) { map[i, j] =

Loading data into a 2D array from text file?

我只是一个虾纸丫 提交于 2021-02-08 11:12:21
问题 I am using C# in a console application. I need to load data from a text file and load it into a 2d array. This is what I tried, but when I try to print out the contents of what gets returned nothing gets printed. public static int[,] LoadMap() { const string path = @"1.txt"; string[] fileLines = File.ReadAllLines(path); int[,] map = new int[fileLines.Length, 15]; string line; for (int i = 0; i < fileLines.Length; ++i) { line = fileLines[i]; for (int j = 0; j < line.Length; ++j) { map[i, j] =

StreamReader and buffer in C#

Deadly 提交于 2021-02-07 12:38:34
问题 I've a question about buffer usage with StreamReader. Here: http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx you can see: "When reading from a Stream, it is more efficient to use a buffer that is the same size as the internal buffer of the stream.". According to this weblog , the internal buffer size of a StreamReader is 2k, so I can efficiently read a file of some kbs using the Read() avoiding the Read(Char[], Int32, Int32) . Moreover, even if a file is big I can construct

StreamReader and buffer in C#

社会主义新天地 提交于 2021-02-07 12:38:30
问题 I've a question about buffer usage with StreamReader. Here: http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx you can see: "When reading from a Stream, it is more efficient to use a buffer that is the same size as the internal buffer of the stream.". According to this weblog , the internal buffer size of a StreamReader is 2k, so I can efficiently read a file of some kbs using the Read() avoiding the Read(Char[], Int32, Int32) . Moreover, even if a file is big I can construct

Close a file after using it with JSON

女生的网名这么多〃 提交于 2021-01-29 15:26:41
问题 I've found that function that correctly work for the JSON parse: var objs = JObject.Load(new JsonTextReader(new StreamReader(JsonPath))) .SelectTokens("*") .Select(t => JsonConvert.DeserializeObject<Cars>(t.ToString())); but it doesn't release the file after use it (so I can not use it for other function) ... I've tried to use the function Close, but seems not working over the object! P.s. i've checked the previous open-one question, releated to this topic, but nobody talk about how to access

How To Use HttpWebRequest/Response To Download A Binary (.exe) File From A Web Server?

感情迁移 提交于 2021-01-26 03:43:21
问题 I am writing a program that needs to download an .exe file from a website and then save it to the hard drive. The .exe is stored on my site and it's url is as follows (it's not the real uri just one I made up for the purpose of this question): http://www.mysite.com/calc.exe After many web searches and fumbling through examples here is the code I have come up with so far: HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(http://www.mysite.com/calc.exe); HttpWebResponse webResponse