Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { stream.WriteByte('0'); WriteString(stream, "foo", Encoding.UTF8); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { var charBuffer = encoding.GetBytes(stringToWrite); stream.Write(charBuffer, 0, charBuffer.Length); } 

You'll need to explicitly specify the encoding to get the bytes in, as String.ToByteArray returns the string as Unicode characters, which is .NET language for "UTF-16LE".NET language for "UTF-16LE", giving you two bytes per character.

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { stream.WriteByte('0'); WriteString(stream, "foo", Encoding.UTF8); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { var charBuffer = encoding.GetBytes(stringToWrite); stream.Write(charBuffer, 0, charBuffer.Length); } 

You'll need to explicitly specify the encoding to get the bytes in, as String.ToByteArray returns the string as Unicode characters, which is .NET language for "UTF-16LE", giving you two bytes per character.

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { stream.WriteByte('0'); WriteString(stream, "foo", Encoding.UTF8); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { var charBuffer = encoding.GetBytes(stringToWrite); stream.Write(charBuffer, 0, charBuffer.Length); } 

You'll need to explicitly specify the encoding to get the bytes in, as String.ToByteArray returns the string as Unicode characters, which is .NET language for "UTF-16LE", giving you two bytes per character.

deleted 118 characters in body
Source Link
CodeCaster
  • 152.6k
  • 24
  • 237
  • 287

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { stream.WriteByte(stream, '0');  WriteString(stream, "foo", Encoding.UTF8); } private void WriteByte(Stream stream, byte byteToWrite) { stream.Write(new[] { byteToWrite }, 0, 1); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { var charBuffer = encoding.GetBytes(stringToWrite); stream.Write(charBuffer, 0, charBuffer.Length); } 

You'll need to explicitly specify the encoding to get the bytes in, as String.ToByteArray returns the string as Unicode characters, which is .NET language for "UTF-16LE", giving you two bytes per character.

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { WriteByte(stream, '0'); WriteString(stream, "foo", Encoding.UTF8); } private void WriteByte(Stream stream, byte byteToWrite) { stream.Write(new[] { byteToWrite }, 0, 1); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { var charBuffer = encoding.GetBytes(stringToWrite); stream.Write(charBuffer, 0, charBuffer.Length); } 

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { stream.WriteByte('0');  WriteString(stream, "foo", Encoding.UTF8); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { var charBuffer = encoding.GetBytes(stringToWrite); stream.Write(charBuffer, 0, charBuffer.Length); } 

You'll need to explicitly specify the encoding to get the bytes in, as String.ToByteArray returns the string as Unicode characters, which is .NET language for "UTF-16LE", giving you two bytes per character.

added 60 characters in body
Source Link
CodeCaster
  • 152.6k
  • 24
  • 237
  • 287

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { WriteByte(stream, '0'); WriteString(stream, "foo", Encoding.UTF8); } private void WriteByte(Stream stream, byte byteToWrite) { stream.Write(new[] { byteToWrite }, 0, 1); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { stream.Write(var charBuffer = encoding.GetBytes(stringToWrite); stream.Write(charBuffer, 0, charBuffer.Length); } 

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { WriteByte(stream, '0'); WriteString(stream, "foo", Encoding.UTF8); } private void WriteByte(Stream stream, byte byteToWrite) { stream.Write(new[] { byteToWrite }); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { stream.Write(encoding.GetBytes(stringToWrite)); } 

BinaryWriter prefixes written data so BinaryReader can read it. Without those prefixes, you must know exactly what you're doing when writing and reading the file.

You can omit both writers and directly write into the file if that's what you want:

using (var stream = new FileStream(_caminho, FileMode.Append, FileAccess.Write)) { WriteByte(stream, '0'); WriteString(stream, "foo", Encoding.UTF8); } private void WriteByte(Stream stream, byte byteToWrite) { stream.Write(new[] { byteToWrite }, 0, 1); } private void WriteString(Stream stream, string stringToWrite, Encoding encoding) { var charBuffer = encoding.GetBytes(stringToWrite); stream.Write(charBuffer, 0, charBuffer.Length); } 
Source Link
CodeCaster
  • 152.6k
  • 24
  • 237
  • 287
Loading