streamreader

How to create copy of file using StreamReader and StreamWriter

喜你入骨 提交于 2019-12-23 09:11:09
问题 I need to use StreamReader to read a .txt file on a console application, then create a new file or backup with a different name but same content. The problem is i cant figure out how to use the content from the first file to place into the new one. (This is for a school thing and im new to C#) using System; using System.IO; namespace UserListCopier { class Program { static void Main() { string fineName = "zombieList.txt"; StreamReader reader = new StreamReader(fineName); int lineNumber = 0;

StreamReader and Portable Class Library

天大地大妈咪最大 提交于 2019-12-23 07:19:31
问题 I am writing a ConfigManager class using Portable Class Libraries. PCL supports StreamReader and StreamWriter classes that I want to use, but the PCL version of those classes do not support passing in a string during construction. PCL also does not support the reader.Close() and writer.Close() . Lastly it doesn't support the FileStream class. So I am looking for an answer to any one of the following questions: How can I get the StreamReader and StreamWriter classes working in a PCL? How can I

Reading large text file very slow

假装没事ソ 提交于 2019-12-23 01:06:58
问题 so I have been given a task of writing a vb program where I read in a large .txt file (anywhere from 500mb to 2GB) and this files usually starts with a 13 digit number then loads of other info after per line. (e.g "1578597500548 info info info info etc.") I must let a user enter a 13 digit number and then my program search's the large file for that number at beginning of each line and if its found write the full line into a new .txt file! My current program works perfectly but I'm noticing my

Read from StreamReader in batches

孤街浪徒 提交于 2019-12-22 08:17:15
问题 I have been running into OutOfMemory Exceptions while trying to load an 800MB text file into a DataTable via StreamReader. I was wondering if there a way to load the DataTable from the memory stream in batches, ie, read the first 10,000 rows of the text file from StreamReader, create DataTable, do something with DataTable, then load the next 10,000 rows into the StreamReader and so on. My googles weren't very helpful here, but it seems like there should be an easy way to do this. Ultimately I

How to take a stringbuilder and convert it to a streamReader?

一个人想着一个人 提交于 2019-12-22 04:42:43
问题 How to take a stringbuilder and convert it to a stream? SO my stringbuilder has to be converted into a : StreamReader stream = ???? Update I tried using a stringreader like: StringReader sr = new StringReader(sb.ToString()); StreamReader stream = new StreamReader(sr); but that doesn't work? 回答1: Use ToString to convert the StringBuilder into a String, and use a StringReader to wrap the String as a Stream. 回答2: If using a StreamReader is a requirement then convert the string to a memory stream

Reading the next line of a file only once

落花浮王杯 提交于 2019-12-21 20:41:42
问题 I have an application that reads information from a text file and then categorizes them and puts them onto a Database. For one category, I need to check the line that comes right after the current line and look for a certain keyword? How do i get to read this line? This should happen when the streamreader has the current line already open.... I'm using c# on VS2010. Edit : All of the code below is in a while (!sReader.EndOfStream) loop string line = sReader.ReadLine(); //Note: this is used

StreamReader get and set position

江枫思渺然 提交于 2019-12-21 11:24:04
问题 i simply want to read a large CSV-File and save the Stream position in a list. After that i have to read the position from the list and set the position of the Streamreader to that char and read a line!! But after i read the first line and return the streamposition with StreamReader r = new StreamReader("test.csv"); r.readLine(); Console.WriteLine(r.BaseStream.Position); i get "177", which are the total chars in the file! (it's only a short examplefile) i didn't found anything like that here

StreamReader get and set position

陌路散爱 提交于 2019-12-21 11:23:06
问题 i simply want to read a large CSV-File and save the Stream position in a list. After that i have to read the position from the list and set the position of the Streamreader to that char and read a line!! But after i read the first line and return the streamposition with StreamReader r = new StreamReader("test.csv"); r.readLine(); Console.WriteLine(r.BaseStream.Position); i get "177", which are the total chars in the file! (it's only a short examplefile) i didn't found anything like that here

C# StreamReader, “ReadLine” For Custom Delimiters

冷暖自知 提交于 2019-12-21 07:13:39
问题 What is the best way to have the functionality of the StreamReader.ReadLine() method, but with custom (String) delimiters? I'd like to do something like: String text; while((text = myStreamReader.ReadUntil("my_delim")) != null) { Console.WriteLine(text); } I attempted to make my own using Peek() and StringBuilder , but it's too inefficient. I'm looking for suggestions or possibly an open-source solution. Thanks. Edit I should have clarified this earlier...I have seen this answer, however, I'd

How to skip invalid characters in stream in Java/Scala?

别说谁变了你拦得住时间么 提交于 2019-12-20 09:54:05
问题 For example I have following code Source.fromFile(new File( path), "UTF-8").getLines() and it throws exception Exception in thread "main" java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException(CoderResult.java:260) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:319) I don't care if some lines were not read, but how to skip invalid chars and continue reading lines? 回答1: You can influence the way that the charset decoding handles