I need to read data from a text file line by line. Each line contains either a string or an integer. I want to use StreamReader to read line by line from the text file and StreamWriter to write it to a binary file. The "write to binary file" part will be easy. The "read from text file line by line" part is the part I need help with.
read a text file line by line
277 Views Asked by user2272380 At
2
There are 2 best solutions below
0
ismellike
On
In c# you can do something like this.
string loc = "idk/where/ever";
using(var sr = new StreamReader(loc))
using(var sw = new StreamWriter(loc+".tmp"))
{
string line;
while((line=sr.ReadLine())!=null)
{
sw.WriteLine(line);
//edit it however you want
}
}
File.Delete(loc);
File.Move(loc+".tmp",loc);
Related Questions in FILE
- Saving FileSystemInfo Array to File
- C programming: Create and write 2D array of files as function
- How can I change a specific line in a file with node js?
- Grabbing Edits from two strings
- In Android, would it be possible to open a file in the 'values' folder and to read its content?
- Using paths bonded to a XCode project to be shared
- Why am i getting these invalid characters before my file data?
- Optimum directory structure for large number of files to display on a page
- C Reading binary file with fread()
- Renaming a File() object in JavaScript
- How to write the current time to a new line of a .txt file on php execution
- introduce c++ into html
- How can I create a simple text file on a windows phone (8.1) that can be accessed trough USB cable?
- Pop-up and download zip file in ASP.NET
- Using access() in C
Related Questions in TEXT
- Delete the extra space after special character in all the lines of text file
- Apply gaussian filter on text
- text show and hide with button php/js
- Get text from a section of a pdf page with IcePdf
- load word file (.docx) in richtextbox
- Display a specific line in a text file - android/java
- how to change text direction to the right slide of switch in android?
- C language - Read specific data from text file
- Read text file from specific position and store in two arrays
- How to animate text
- Detect repetition in text string / copied text
- Use MATLAB's webread to login to website and extract text
- LWJGL Drawing colored text to the screen issue
- Hide part of text temporarily, show after user clicks certain element
- Reading text file in java using scanner
Related Questions in BINARYREADER
- Simple binary reader-writer code not working
- Detecting an invalid char
- Read Rijndael encrypted file in memory itself to decrypt
- C# Using BinaryReader to read color byte values of a bitmap image
- Empty array with BinaryReader on UploadedFile in c#
- C# client server application, BinaryReader throws an exception
- read a text file line by line
- C# BinaryReader.ReadChar throws "System.ArgumentException: The output char buffer is too small" when reading NetworkStream
- What does BE or LE mean in Buffer functions?
- Is it possible to detect if BinaryReader.ReadBytes(int) reaches the end of a stream?
- Method difference between languages (Python->C#)
- How do I read bit flags mixed with data?
- What does BinaryReader do if the bytes I am reading aren't present yet?
- C# BinaryReader.ReadString on a network socket
- How to convert a BinaryReader to Stream in C#?
Related Questions in BINARYWRITER
- Java - Write a string prefixed with the 7 bit encoded length
- Simple binary reader-writer code not working
- Open a PDF in new tab from URL from my MVC Controller [EDITED]
- catching errors with using BinaryWriter
- Writing binary data to ftp location
- Accessing base memorystream [for read] in a binarywriter
- How BinaryWriter in c# saves its content?
- read a text file line by line
- Converting XLS to PDF: Getting "Data index must be a valid index in the field" exception during GetBytes()
- Does ADODB.Stream chunks conflicts with Response.Buffer?
- What is the equivalent of BinaryWriter.Write() from C# in Python?
- BinaryWriter Unusual hex
- How to use BinaryReader and correctly input data into file?
- Serialize non-primitive objects using BinaryWriter
- MemoryStream read/write and data length
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
It's all built into StreamReader: