binarywriter

C# [anonymous\generic] object to byte[] without BinaryFormatter [in .NET 4.5]?

喜欢而已 提交于 2020-01-04 02:15:14
问题 BinaryFormatter works great, but doesn't exist in Portable class libraries for .NET 4.5. I've read that it IS in .NET 4.6 Portable. I have not confirmed this because when I change to 4.6 in my project settings, I get a warning message that "4.5 will be automatically targeted" unless I de-select Silverlight, WindowsPhone, Windows Universal, Xamarin, etc), so I can only target .NET 4.6 Portable if I'm NOT targeting additional platforms, thus defeating the purpose. Here is my original

Seeking a particular value when using BinaryWriter

南楼画角 提交于 2019-12-25 07:39:37
问题 I find it difficult to express myself so I'll jump right into the code FileStream stream = new FileStream("//ignoreThis//demo.bin", FileMode.Append, FileAccess.Write, FileShare.Write)); BinaryWriter writer = new BinaryWriter(stream); writer.Write(myNum); writer.Write(myString); I can call this method several times and I know that every time I do so, it will add the new data at the end of the file 'demo.bin'. Now I'm trying to write a method where I can seek to my 3rd instance (I'm not sure if

Unable to read beyond the end of the stream is caused when use readbinary

给你一囗甜甜゛ 提交于 2019-12-24 21:28:11
问题 I am trying to send a value by socket .So i have two parts in my project Client and server . The client sends a value to server using this code : NetworkStream networkStream = socketForServer.GetStream(); System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(networkStream); //------ int messageSource = 0; int messageDesitination = 0; int interlockingId = 0; int trackId = 0; int trainId = 2; int direction = 0; int messageType = 0; int informationType = 0; int dateTime = 0; foreach

Binary Reader and Writer open at same time?

匆匆过客 提交于 2019-12-22 09:00:10
问题 I'm writing code that deals with a file that uses hashes. I need to read a chunk, then hash it, then write it, then read another chunk, etc. In other words, I need to do a lot of reading and writing. I'm sure this is really simple, but I just wanted to run it by the pros... Is it possible, and acceptable to do something like: BinaryReader br = new BinaryReader (File.OpenRead(path)); BinaryWriter bw = new BinaryWriter (File.OpenWrite(path)); br.dostuff(); bw.dostuff(); I remember running into

Bit-Based BinaryWriter in C#

纵然是瞬间 提交于 2019-12-12 08:08:07
问题 I'm working on a bit-based B/W/Greyscale Pre-Compiled font format, and was having issues with either reading or writing the format, (I've not been able to determine where the issue was. (I do have a B/W bit-based version working, but an Aliased font doesn't look too good, as you can imagine, especially when working with a 320x200 pixel screen) ) but decided that just using a BinaryWriter would be much easier than writing to a bool[] when I pulled the image data. The basic format of a pixel in

Write one single bit to binary file using BinaryWriter

走远了吗. 提交于 2019-12-10 10:54:24
问题 I want to write one single bit to a binary file. using (FileStream fileStream = new FileStream(@"myfile.bin", FileMode.Create)) using (BinaryWriter binaryWriter = new BinaryWriter(fileStream)) { binaryWriter.Write((bool)10); } Something like binaryWriter.Write((bit)1); When I use binaryWriter.Write((bool)1) the file has one byte, but I want to write one single bit. Is this possible? 回答1: You cannot store only 1 bit in a file. Almost all modern filesystems and hardware store data in segments

Write one single bit to binary file using BinaryWriter

左心房为你撑大大i 提交于 2019-12-06 09:59:07
I want to write one single bit to a binary file. using (FileStream fileStream = new FileStream(@"myfile.bin", FileMode.Create)) using (BinaryWriter binaryWriter = new BinaryWriter(fileStream)) { binaryWriter.Write((bool)10); } Something like binaryWriter.Write((bit)1); When I use binaryWriter.Write((bool)1) the file has one byte, but I want to write one single bit. Is this possible? You cannot store only 1 bit in a file. Almost all modern filesystems and hardware store data in segments of 8 bits, aka bytes or octets. If you want store a bit value in a file, store either 1 or 0 as a byte

Binary Reader and Writer open at same time?

…衆ロ難τιáo~ 提交于 2019-12-05 16:54:46
I'm writing code that deals with a file that uses hashes. I need to read a chunk, then hash it, then write it, then read another chunk, etc. In other words, I need to do a lot of reading and writing. I'm sure this is really simple, but I just wanted to run it by the pros... Is it possible, and acceptable to do something like: BinaryReader br = new BinaryReader (File.OpenRead(path)); BinaryWriter bw = new BinaryWriter (File.OpenWrite(path)); br.dostuff(); bw.dostuff(); I remember running into some sort of conflicting file streams error when experimenting with opening and writing to files, and I

Using BinaryWriter on an Object

旧巷老猫 提交于 2019-12-04 03:58:37
问题 My application is a small C# database, and I'm using BinaryWriter to save the database to a file which is working fine with the basic types such as bool, uint32 etc. Although I've got a variable that is of type Object (allowing the user to store any data type), however as my application doesn't (nor needs to) know the real type of this variable, I'm unsure how to write it using BinaryWriter . Is there a way I could perhaps grab the memory of the variable and save that? Would that be reliable?

Bit-Based BinaryWriter in C#

非 Y 不嫁゛ 提交于 2019-12-03 14:29:28
I'm working on a bit-based B/W/Greyscale Pre-Compiled font format, and was having issues with either reading or writing the format, (I've not been able to determine where the issue was. (I do have a B/W bit-based version working, but an Aliased font doesn't look too good, as you can imagine, especially when working with a 320x200 pixel screen) ) but decided that just using a BinaryWriter would be much easier than writing to a bool[] when I pulled the image data. The basic format of a pixel in the file looks like this: 1 - White Pixel (Shortest, as this would be most of the pixels) 00 - Black