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
279 views Asked by user2272380 At
2
There are 2 answers
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
- Helpt with reading files
- Why can't I use the file pointer after the first read attempt fails?
- Can't read the file using std::wifstream C++
- How can the scanner reread the entire file after it has already executed hasNextLine once?
- What is 'Invalid Load Key, '\x00'
- php $_FILE variable undefined index
- Data loaded from the file is not returned in the correct order
- File splitting and encryption
- Optimizing an s5cmd command that uses awk to generate a text file
- segmentation fault while reading in text file ( c++ )
- File.OpenText is adding C:\ to the front which is an error
- UTF-8 issue with excel
- How to upload files to MediaWiki APIs in Rust?
- No such file or directory: '/tmp/tmp_ejr26m6.upload.mp3' in Django
- Problems accessing zip files on the react front end from express backend
Related Questions in TEXT
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- How to increase quality of mathjax output?
- How to appropriately handle newlines and the escaping of them?
- How to store data with lots of subdata but keep easy and simple access in python
- Can I make this kind of radio button?
- I am findind it dificult to create a box containing text
- Replacing Text using Javascript
- How to set text inside a div using JavaScript and CSS
- How to get new text input after entering a password in a tab?
- How can I get my hero section to look like this?
- Find text and numbers Formatted: "Case: BE########" and format them, regardless of the number
- Auto style text in flutter
- Text analytics and Insights
- Combine an audio and a text file as one single file
- How to align side text and table horizontally in R-markdown
Related Questions in BINARYREADER
- asp classic BinaryRead with hebrew charachters has wrong encoding
- Why does binary reader put all the content of my 2d array into a single array row?
- How to read a stream of bytes when you already know the structure of the bytes in C#?
- C# BinaryReader end of Stream
- BinaryReader returning very large doubles. What type of value should I be returning?
- Why I am not able to get the data back which I have saved to dat file using BinaryReader in C#? How to Implement this properly using BinaryReader?
- Can't read data correctly with BinaryReader from WebRequest
- Process and delete lines from file, stop if CancellationToken is send
- Slow ReadLine by `\n` on BinaryReader
- Is there any way to read information stored in binary (.bin) file?
- How to read whole binary file (not only the first variables) including string, long and int
- (VB.NET) How to read binary file (not like 00 C8 but rather 51200) - Automotive Chip Tuning Software
- Is it possible to detect if BinaryReader.ReadBytes(int) reaches the end of a stream?
- Binaryreader Readint32() returns too big value or -ve value
- C# BinaryReader performanceboost alternatives
Related Questions in BINARYWRITER
- Response BinaryWrite does not allow the splitting column in export excel. It creates single column of entire data
- BinaryWriter not writing to file and I can't figure out why
- Need for a fast writing of binary data to a file
- C# BinaryWriter Save as PFM image file
- Why does binary reader put all the content of my 2d array into a single array row?
- How to operate with binary files faster?
- Serialize non-primitive objects using BinaryWriter
- How to save a char[25] when it contains only 6 chars C#
- Why I am not able to get the data back which I have saved to dat file using BinaryReader in C#? How to Implement this properly using BinaryReader?
- Exporting multiple blob records and saving to disk
- How do I embed Assembly Info into a file created by a C# program
- What is the equivalent of BinaryWriter.Write() from C# in Python?
- Does ADODB.Stream chunks conflicts with Response.Buffer?
- Converting XLS to PDF: Getting "Data index must be a valid index in the field" exception during GetBytes()
- ByteBuffer.wrap().getInt() equivalent in c#
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?
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)
It's all built into StreamReader: