Questions tagged [binarywriter]
170 questions
2
votes
2 answers
ByteBuffer.wrap().getInt() equivalent in c#
Java
byte[] input = new byte[] { 83, 77, 45, 71, 57, 51, 53, 70 };
int buff = ByteBuffer.wrap(input).getInt();
Output: 1397566791
C#
byte [] array = { 83, 77, 45, 71, 57, 51, 53, 70 };
MemoryStream stream = new MemoryStream();
using (BinaryWriter…

xoxoxs
- 23
- 2
2
votes
2 answers
PowerShell 7.0 how to compute hashsum of a big file read in chunks
The script should copy files and compute hash sum of them.
My goal is make the function which will read the file once instead of 3 ( read_for_copy + read_for_hash + read_for_another_copy ) to minimize network load.
So I tried read a chunk of file…

kostyan
- 21
- 2
2
votes
2 answers
Need help using Read7BitEncodedInt
I've been searching for 2 hours or better for a way to use the Read7BitEncodedInt method for this. I need to use it somehow to reduce my file size (in this case likely by 100mb or more). I was also looking at using the ReadString method since it…

Grimbly
- 194
- 8
2
votes
2 answers
Read and write of binary file in c#
I have read a binary file in using C# as per the following code. Then I tried to write this binary data in another binary file. But I found that when I opened these 2 files in Winmerge, there is a difference in both binary files. i.e read file and…

Ganesh Chavan
- 57
- 1
- 1
- 6
2
votes
2 answers
Best way to read a short array from disk in C#?
I have to write 4GB short[] arrays to and from disk, so I have found a function to write the arrays, and I am struggling to write the code to read the array from the disk. I normally code in other languages so please forgive me if my attempt is a…

bandybabboon
- 2,210
- 1
- 23
- 33
2
votes
2 answers
How Write a List to binary file (4 bytes long)?
I need to write a List of ints to a binary file of 4 bytes in length, so, I need to make sure that the binary file is correct, and I do the following:
using (FileStream fileStream = new FileStream(binaryFileName, FileMode.Create)) // destiny file…

ale
- 3,301
- 10
- 40
- 48
2
votes
1 answer
How to get the length of written bytes with BinaryWriter?
Considering a simple BinaryWriter procedure:
using (BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
writer.Write(10000);
writer.Write("Temp");
writer.Write(30);
…

Pythonic
- 49
- 5
2
votes
2 answers
How to use System.IO.BinaryWriter in C# with array of template/generic type?
I was wondering if there is any way to use System.IO.BinaryWriter in C# to write an array of template/generic type?
For example, I have a buffer in a templated struct:
T[] buffer
T is typically either bool or byte. The idea was to have methods for…

ares_games
- 1,019
- 2
- 15
- 32
2
votes
1 answer
A custom binarywriter or a custom numeric datatype?
I have to query an oracle database for various numeric values and dump them with my c# console app in a binary file with a custom format. Depending on the business data I need to encode the numeric value on 1 byte length,2 byte length,3 byte…

Dypso
- 563
- 1
- 5
- 15
2
votes
4 answers
Can't write to file using binarywriter
Why does this code not write my string to the file:
string file = "Myfile.txt";
MemoryStream ms = new MemoryStream();
void writeToFile(string text)
{
System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
…

Tony The Lion
- 61,704
- 67
- 242
- 415
2
votes
0 answers
Java - Write a string prefixed with the 7 bit encoded length
I am trying to recreate C#'s BinaryWriter's Write function on a string in Java.
The C# method writes a string's length encoded in 7-bit format, and then the string. Is there any way I can implement this in Java?
I've tried implementing it like so,…

lanour
- 123
- 1
- 5
2
votes
1 answer
catching errors with using BinaryWriter
I am using a using with the BinaryWriter as follows:
using (BinaryWriter writer = new BinaryWriter(File.Open(configData.RxOutFn, FileMode.Create)))
{
// Do Something
}
Sometimes I have the file open in another app, and the Create fails, how can…

Andy
- 259
- 1
- 4
- 16
2
votes
3 answers
Display JPEG using Response.BinaryWrite
I'm displaying an image like this:
counter.asp is doing a hit-counter do determine how often the image was displayed (I'll replace it with a modrewrite URL).
The problem: in the counter.asp script I need to send the actual…

Fuxi
- 7,611
- 25
- 93
- 139
2
votes
1 answer
BinaryReader in c# reads '\0' between all characters of a string
I am trying to write and read a binary file using c# BinaryWriter and BinaryReader classes.
When I am storing a string in file, it is storing it properly, but when I am trying to read it is returning a string which has '\0' character on every…

Bosco
- 3,835
- 6
- 25
- 33
2
votes
2 answers
BinaryWriter to overwrite an existing file c#
To write a picture on the memory of my pocket pc i use the following code:
pic = (byte[])myPicutureFromDatabase;
using (var fs = new BinaryWriter(new FileStream(filepath, FileMode.Append, FileAccess.Write)))
{
fs.Write(pic);
fs.Flush();
…

user1788654
- 311
- 2
- 5
- 13