이 있습니까 당신이하는 당신의 바이트 배열을 인코딩 알고는 저장됩니까?
당신은 여기 MSDN 예를
using System;
using System.IO;
using System.Text;
public class Example
{
const int MAX_BUFFER_SIZE = 2048;
static Encoding enc8 = Encoding.UTF8;
public static void Main()
{
FileStream fStream = new FileStream(@".\Utf8Example.txt", FileMode.Open);
string contents = null;
// If file size is small, read in a single operation.
if (fStream.Length <= MAX_BUFFER_SIZE) {
Byte[] bytes = new Byte[fStream.Length];
fStream.Read(bytes, 0, bytes.Length);
contents = enc8.GetString(bytes);
}
// If file size exceeds buffer size, perform multiple reads.
else {
contents = ReadFromBuffer(fStream);
}
fStream.Close();
Console.WriteLine(contents);
}
private static string ReadFromBuffer(FileStream fStream)
{
Byte[] bytes = new Byte[MAX_BUFFER_SIZE];
string output = String.Empty;
Decoder decoder8 = enc8.GetDecoder();
while (fStream.Position < fStream.Length) {
int nBytes = fStream.Read(bytes, 0, bytes.Length);
int nChars = decoder8.GetCharCount(bytes, 0, nBytes);
char[] chars = new char[nChars];
nChars = decoder8.GetChars(bytes, 0, nBytes, chars, 0);
output += new String(chars, 0, nChars);
}
return output;
}
}
// The example displays the following output:
// This is a UTF-8-encoded file that contains primarily Latin text, although it
// does list the first twelve letters of the Russian (Cyrillic) alphabet:
//
// А б в г д е ё ж з и й к
//
// The goal is to save this file, then open and decode it as a binary stream.
편집
하면 16 진수 형식으로 바이트 배열을 인쇄하려면, BitConverter 당신이 양식을 찾고있는 것이다 Encoding.GetString 방법
필요 여기에 MSDN 예
// Example of the BitConverter.ToString(byte[ ]) method.
using System;
class BytesToStringDemo
{
// Display a byte array with a name.
public static void WriteByteArray(byte[ ] bytes, string name)
{
const string underLine = "--------------------------------";
Console.WriteLine(name);
Console.WriteLine(underLine.Substring(0,
Math.Min(name.Length, underLine.Length)));
Console.WriteLine(BitConverter.ToString(bytes));
Console.WriteLine();
}
public static void Main()
{
byte[ ] arrayOne = {
0, 1, 2, 4, 8, 16, 32, 64, 128, 255 };
byte[ ] arrayTwo = {
32, 0, 0, 42, 0, 65, 0, 125, 0, 197,
0, 168, 3, 41, 4, 172, 32 };
byte[ ] arrayThree = {
15, 0, 0, 128, 16, 39, 240, 216, 241, 255,
127 };
byte[ ] arrayFour = {
15, 0, 0, 0, 0, 16, 0, 255, 3, 0,
0, 202, 154, 59, 255, 255, 255, 255, 127 };
Console.WriteLine("This example of the " +
"BitConverter.ToString(byte[ ]) \n" +
"method generates the following output.\n");
WriteByteArray(arrayOne, "arrayOne");
WriteByteArray(arrayTwo, "arrayTwo");
WriteByteArray(arrayThree, "arrayThree");
WriteByteArray(arrayFour, "arrayFour");
}
}
/*
This example of the BitConverter.ToString(byte[ ])
method generates the following output.
arrayOne
--------
00-01-02-04-08-10-20-40-80-FF
arrayTwo
--------
20-00-00-2A-00-41-00-7D-00-C5-00-A8-03-29-04-AC-20
arrayThree
----------
0F-00-00-80-10-27-F0-D8-F1-FF-7F
arrayFour
---------
0F-00-00-00-00-10-00-FF-03-00-00-CA-9A-3B-FF-FF-FF-FF-7F
*/
을 데이터 매트릭스와 같은 뷰를 생성합니다 이진 파일 형식을 사용합니까? – tomfanning
문제는 시도한 솔루션을 알 수 없다는 것입니다. 나는. 보셨습니까 [이 답변] (http://stackoverflow.com/a/311179/15498)? 또한 바이너리 리더의 메모리 스트림에 바이트 배열을 래핑하는 것으로, 바이트 배열로 다시 변환 할 수 있습니까? –
@Damien_The_Unbeliever - 허용 된 답변의 두 가지 방법이 실제로 작동합니다. 하지만 약 10kb 파일에서만 작동합니다. 다른 것은 가능하며 실행하기에는 너무 오래 걸립니다. (1 분 이상 읽음). 아이디어가 있으십니까? – Anteara