Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- namespace PaddingFF
- {
- class Program
- {
- static void Main(string[] args)
- {
- FileStream fs = new FileStream(
- @"test.bin", FileMode.Open, FileAccess.Read);
- int fileSize = (int)fs.Length; // ファイルのサイズ
- byte[] buf = new byte[fileSize]; // データ格納用配列
- int readSize; // Readメソッドで読み込んだバイト数
- int remain = fileSize; // 読み込むべき残りのバイト数
- int bufPos = 0; // データ格納用配列内の追加位置
- Console.WriteLine(fileSize);
- Console.WriteLine(fileSize < 64*1024*1024
- ? "パディングします。" : "パディングしません。");
- while (remain > 0)
- {
- // Console.WriteLine(remain);
- // 1024Bytesずつ読み込む
- readSize = fs.Read(buf, bufPos, Math.Min(1024, remain));
- bufPos += readSize;
- remain -= readSize;
- }
- fs.Dispose();
- if(fileSize < 64 * 1024 * 1024)
- {
- // パディング 0xFF
- byte[] byteArray = Enumerable.Repeat<byte>(0xFF, 64 * 1024 * 1024).ToArray();
- for(int i = 0; i < fileSize; i++)
- {
- byteArray[i] = buf[i];
- }
- //ファイルを作成して書き込む
- //ファイルが存在しているときは、上書きする
- System.IO.FileStream fs2 = new System.IO.FileStream(
- @"padding.bin",
- System.IO.FileMode.Create,
- System.IO.FileAccess.Write);
- //バイト型配列の内容をすべて書き込む
- fs2.Write(byteArray, 0, byteArray.Length);
- //閉じる
- fs2.Close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment