binaryreader

C# - Binary reader in Big Endian?

北慕城南 提交于 2019-11-27 04:03:39
I'm trying to improve my understanding of the STFS file format by using a program to read all the different bits of information. Using a website with a reference of which offsets contain what information, I wrote some code that has a binary reader go through the file and place the values in the correct variables. The problem is that all the data is SUPPOSED to be Big Endian, and everything the binary reader read is Little Endian. So, what's the best way to go about fixing this? Can I create a mimic class of Binary reader that returns a reversed array of bytes? Is there something I can change

An elegant way to consume (all bytes of a) BinaryReader?

北城以北 提交于 2019-11-27 01:47:28
Is there an elegant to emulate the StreamReader.ReadToEnd method with BinaryReader ? Perhaps to put all the bytes into a byte array? I do this: read1.ReadBytes((int)read1.BaseStream.Length); ...but there must be a better way. Scott Rippey Simply do: byte[] allData = read1.ReadBytes(int.MaxValue); The documentation says that it will read all bytes until the end of the stream is reached. Update Although this seems elegant, and the documentation seems to indicate that this would work, the actual implementation (checked in .NET 2, 3.5, and 4) allocates a full-size byte array for the data, which

StreamReader vs BinaryReader?

橙三吉。 提交于 2019-11-26 15:39:32
问题 Both StreamReader and BinaryReader can be used to get data from binary file ( for example ) BinaryReader : using (FileStream fs = File.Open(@"c:\1.bin",FileMode.Open)) { byte[] data = new BinaryReader(fs).ReadBytes((int)fs.Length); Encoding.getstring.... } StreamReader : using (FileStream fs = File.Open(@"c:\1.bin",FileMode.Open)) { using (StreamReader sr = new StreamReader(fs,Encoding.UTF8)) { var myString=sr.ReadToEnd(); } } What is the difference and when should I use which ? 回答1: Both

An elegant way to consume (all bytes of a) BinaryReader?

别等时光非礼了梦想. 提交于 2019-11-26 12:28:41
问题 Is there an elegant to emulate the StreamReader.ReadToEnd method with BinaryReader ? Perhaps to put all the bytes into a byte array? I do this: read1.ReadBytes((int)read1.BaseStream.Length); ...but there must be a better way. 回答1: Simply do: byte[] allData = read1.ReadBytes(int.MaxValue); The documentation says that it will read all bytes until the end of the stream is reached. Update Although this seems elegant, and the documentation seems to indicate that this would work, the actual

C# - Binary reader in Big Endian?

馋奶兔 提交于 2019-11-26 10:58:16
问题 I\'m trying to improve my understanding of the STFS file format by using a program to read all the different bits of information. Using a website with a reference of which offsets contain what information, I wrote some code that has a binary reader go through the file and place the values in the correct variables. The problem is that all the data is SUPPOSED to be Big Endian, and everything the binary reader read is Little Endian. So, what\'s the best way to go about fixing this? Can I create

How to convert byte array to string [duplicate]

和自甴很熟 提交于 2019-11-26 00:27:06
问题 This question already has answers here : How to convert UTF-8 byte[] to string? (14 answers) Closed 6 years ago . I created a byte array with two strings. How do I convert a byte array to string? var binWriter = new BinaryWriter(new MemoryStream()); binWriter.Write(\"value1\"); binWriter.Write(\"value2\"); binWriter.Seek(0, SeekOrigin.Begin); byte[] result = reader.ReadBytes((int)binWriter.BaseStream.Length); I want to convert result to a string. I could do it using BinaryReader , but I