binaryreader

Byte[stream.length] - out of memory exception, best way to solve?

流过昼夜 提交于 2021-02-11 16:42:28
问题 i am trying to read the stream of bytes from a file. However when I try to read the bytes I get a The function evaluation was disabled because of an out of memory exception Quite straightforward. However, what is the best way of getting around this problem? Is it too loop around the length at 1028 at a time? Or is there a better way? The C# I am using BinaryReader br = new BinaryReader(stream fs); // The length is around 600000000 long Length = fs.Length; // Error here bytes = new byte[Length

Byte[stream.length] - out of memory exception, best way to solve?

被刻印的时光 ゝ 提交于 2021-02-11 16:40:16
问题 i am trying to read the stream of bytes from a file. However when I try to read the bytes I get a The function evaluation was disabled because of an out of memory exception Quite straightforward. However, what is the best way of getting around this problem? Is it too loop around the length at 1028 at a time? Or is there a better way? The C# I am using BinaryReader br = new BinaryReader(stream fs); // The length is around 600000000 long Length = fs.Length; // Error here bytes = new byte[Length

How do I know current offset of BinaryReader in C#?

旧城冷巷雨未停 提交于 2021-02-08 13:34:35
问题 I have source below: public static void DisplayValues() { float aspectRatio; string tempDirectory; int autoSaveTime; bool showStatusBar; if (File.Exists(fileName)) { using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open))) { aspectRatio = reader.ReadSingle(); tempDirectory = reader.ReadString(); ------------------------------------------------> I want to know current offset. autoSaveTime = reader.ReadInt32(); showStatusBar = reader.ReadBoolean(); } Console.WriteLine(

How do I know current offset of BinaryReader in C#?

不想你离开。 提交于 2021-02-08 13:32:34
问题 I have source below: public static void DisplayValues() { float aspectRatio; string tempDirectory; int autoSaveTime; bool showStatusBar; if (File.Exists(fileName)) { using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open))) { aspectRatio = reader.ReadSingle(); tempDirectory = reader.ReadString(); ------------------------------------------------> I want to know current offset. autoSaveTime = reader.ReadInt32(); showStatusBar = reader.ReadBoolean(); } Console.WriteLine(

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

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