1 2 3 4 5 6 7 8 9 10 |
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
| byte[] byt = new byte[1024]; |
| "C:\\data\\work.bin" |
| パラメータ | 説明 |
|---|---|
| leng | 実際に入力されたバイト長を格納する領域 |
| byt | 入力データを格納する byte 配列 |
| 0 | 入力開始位置(オフセット) |
| byt.Length | 最大入力バイト長 |
/**************************************************************/
/*★ Binary データを入力してコンソールに表示する 前田 稔 ★*/
/**************************************************************/
using System;
using System.IO; // for File, StreamReader
class BinFileRead
{
public static int Main()
{
string file_name = "C:\\data\\work.bin";
byte[] byt = new byte[1024];
int leng;
if (!File.Exists(file_name)) return -1; //ファイルの有無をチェック
FileStream reader = File.Open(file_name,FileMode.Open);
leng= reader.Read(byt,0,byt.Length);
reader.Close();
for(int i=0; i<leng; i++) Console.WriteLine("{0}",byt[i]);
Console.ReadLine();
return 0;
}
}
|
![]()
// File Copy 関数
static int File_Copy(string i_file, string o_file)
{
byte[] byt = new byte[4096];
int leng;
if (!File.Exists(i_file)) return -1; //ファイルの有無をチェック
FileStream reader = File.Open(i_file,FileMode.Open);
FileStream writer = File.Create(o_file);
while(true)
{ leng= reader.Read(byt,0,byt.Length);
writer.Write(byt,0,leng);
if (leng < byt.Length) break;
}
reader.Close();
writer.Close();
return 0;
}
|
public static int Main()
{
string input_file = "C:\\TMP\\w1.jpg";
string output_file = "C:\\TMP\\ww1.jpg";
if (File_Copy(input_file,output_file)==-1)
Console.Write("Input File Error");
return 0;
}
|
![]()