binarywriter

Difference between BinaryWriter and BinaryFormatter.Serialize?

强颜欢笑 提交于 2020-12-05 08:26:09
问题 I'm new to object serialization, and in the course of my learning how to read from and write to a file (deserialize and serialize) using BinaryFormatter , I came across BinaryReader and BinaryWriter , which seemed to be doing the same thing. Is there some subtle difference between BinaryFormatter.Serialize() and BinaryWriter ? Or is BinaryWriter just a more compact way performing the the same action as BinaryFormatter.Serialize() ? 回答1: BinaryWriter is used to write primitive types in binary

Difference between BinaryWriter and BinaryFormatter.Serialize?

我的未来我决定 提交于 2020-12-05 08:25:12
问题 I'm new to object serialization, and in the course of my learning how to read from and write to a file (deserialize and serialize) using BinaryFormatter , I came across BinaryReader and BinaryWriter , which seemed to be doing the same thing. Is there some subtle difference between BinaryFormatter.Serialize() and BinaryWriter ? Or is BinaryWriter just a more compact way performing the the same action as BinaryFormatter.Serialize() ? 回答1: BinaryWriter is used to write primitive types in binary

read a text file line by line

被刻印的时光 ゝ 提交于 2020-05-19 02:34:12
问题 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. 回答1: It's all built into StreamReader: using (var sr = new StreamReader(myFile)) { string line; while ((line = sr.ReadLine()) != null) { // line is the text line

read a text file line by line

為{幸葍}努か 提交于 2020-05-19 02:33:00
问题 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. 回答1: It's all built into StreamReader: using (var sr = new StreamReader(myFile)) { string line; while ((line = sr.ReadLine()) != null) { // line is the text line

How To Write A String Of Binary To File C#

China☆狼群 提交于 2020-03-22 01:50:03
问题 I Have A String Of Binary Number Like temp = "0101110011" And I Want To Save That As File this Temp Have 10 char And How Can I Save This string To file With 10 Bit Length ? void Save_Data(string temp) { bool[] BoolArray = new bool[temp.Length]; BitArray Barray = new BitArray(BoolArray.Length); char[] ch = temp.ToCharArray(); for (int i = 0; i < temp.Length; i++) { if (ch[i] == '0') { Barray[i] = false; } else { Barray[i] = true; } } Stream stream = new FileStream("D:\\test.dat", FileMode

How To Write A String Of Binary To File C#

↘锁芯ラ 提交于 2020-03-22 01:49:31
问题 I Have A String Of Binary Number Like temp = "0101110011" And I Want To Save That As File this Temp Have 10 char And How Can I Save This string To file With 10 Bit Length ? void Save_Data(string temp) { bool[] BoolArray = new bool[temp.Length]; BitArray Barray = new BitArray(BoolArray.Length); char[] ch = temp.ToCharArray(); for (int i = 0; i < temp.Length; i++) { if (ch[i] == '0') { Barray[i] = false; } else { Barray[i] = true; } } Stream stream = new FileStream("D:\\test.dat", FileMode

How To Write A String Of Binary To File C#

北战南征 提交于 2020-03-22 01:47:35
问题 I Have A String Of Binary Number Like temp = "0101110011" And I Want To Save That As File this Temp Have 10 char And How Can I Save This string To file With 10 Bit Length ? void Save_Data(string temp) { bool[] BoolArray = new bool[temp.Length]; BitArray Barray = new BitArray(BoolArray.Length); char[] ch = temp.ToCharArray(); for (int i = 0; i < temp.Length; i++) { if (ch[i] == '0') { Barray[i] = false; } else { Barray[i] = true; } } Stream stream = new FileStream("D:\\test.dat", FileMode

BinaryWriter problem - “code adds some byte between Write() method”

牧云@^-^@ 提交于 2020-01-14 06:48:38
问题 I am try to do some code using BinaryWriter and Then BinaryReader. When I wanna write I use method Write(). But the problem is that between two lines of Write method there appears a new byte which is in ASCII table in decimal 31 (sometines 24). You can see it on this image: You can see that byte at index 4 (5th byte) is of ASCII decimal value 31. I didnt insert it there . As you can see 1st 4 bytes are reserved for a number (Int32), next are other data (some text mostly - this is not

BinaryWriter problem - “code adds some byte between Write() method”

懵懂的女人 提交于 2020-01-14 06:48:03
问题 I am try to do some code using BinaryWriter and Then BinaryReader. When I wanna write I use method Write(). But the problem is that between two lines of Write method there appears a new byte which is in ASCII table in decimal 31 (sometines 24). You can see it on this image: You can see that byte at index 4 (5th byte) is of ASCII decimal value 31. I didnt insert it there . As you can see 1st 4 bytes are reserved for a number (Int32), next are other data (some text mostly - this is not

I'd like to use ifstream and ofstream in C++ to mimic C#'s BinaryReader / BinaryWriter functionality

女生的网名这么多〃 提交于 2020-01-05 04:34:18
问题 I'm looking for a way to write floats/ints/strings to a file and read them as floats/ints/strings. (basically read/write as ios::binary). 回答1: I subclassed ifstream and ofstream : ibfstream and obfstream . I made a little helper class that would detect the endianness of the machine I was compiling/running on. Then I added a flag for ibfstream and obfstream that indicated whether bytes in primitive types should be flipped. These classes also had methods to read/write primitive types and arrays