2017-07-19 4 views
-1

を作成します。私は次のことを許可するバイト配列を作成するいくつかの助けた後、午前奇数バイト配列

  • バイト1-2:ファイル名
  • の長さを指定する整数、nは、
  • 3 - N + 2:ファイル
  • N + 3の名前 - N + 10:ファイル
  • N + 11の最終更新日 - N + 12:整数で1
  • N + 13 - n + 16:ファイルデータ長の長整数
  • n + 17 - n + 20:値0の長整数
  • n + 21 - end:ファイルの内容。

ファイルをバイト配列に配置する次のコードはすでにありますが、これは最後の部分です。

ご協力いただければ幸いです。

答えて

0

BinaryReaderとの関係数値が16進数値かアスキー番号(またはビッグ/リトルエンディアン)か分からないので少し推測しています。コードには少し微調整が必​​要な場合があります。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.IO; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string URL = "enter you url here"; 
      FileStream sReader = File.OpenRead(URL); 
      BinaryReader reader = new BinaryReader(sReader); 

      int filenameLength = reader.ReadInt16(); 
      string filename = Encoding.UTF8.GetString(reader.ReadBytes(filenameLength)); 
      int year = int.Parse(Encoding.UTF8.GetString(reader.ReadBytes(4))); 
      int month = int.Parse(Encoding.UTF8.GetString(reader.ReadBytes(2))); 
      int day = int.Parse(Encoding.UTF8.GetString(reader.ReadBytes(2))); 
      DateTime date = new DateTime(year, month, day); 
      short number1 = reader.ReadInt16(); 
      int number2 = reader.ReadInt32(); 
      byte[] data = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position + 1)); 

     } 


    } 
} 
+0

OK、私はコードが正常に動作していないようにコピーしました。私はここに「あなたのURLを入力してください」をc:\\ temp \\ file_name.pdfに置き換え、文字列ファイル名の行にエラーが発生します。 何かがありません –

+0

filenameLengthの値を確認してください。長さはおそらくファイルサイズよりも大きいでしょう。実際のバイト数が後方にある(little/bigエンディアン)か長さがasciiかどうかはわかりません。 – jdweng

関連する問題