バイナリファイルをバイト配列に読み込む
Category - C# のメモ - [2]
バイナリファイルをバイト配列に読み込みます。
// ======================================================================
// ファイル(パス)を指定してバイナリデータを読み込んで返す
// ======================================================================
/// <summary>
/// ファイル(パス)を指定してバイナリデータを読み込んで返す。
/// 成功:nResult に 1を格納。 失敗:nResult に -1を格納。 ファイル存在しない:nResult に 0を格納。
/// </summary>
/// <param name="sFilePath">ファイル(パス)</param>
/// <returns>byte[]</returns>
public static byte[] ReadFileBin(string sFilePath, ref short nResult)
{
short nRlt = -1;
try
{
if (File.Exists(sFilePath))
{
byte[] data = File.ReadAllBytes(sFilePath); // 読み込み
nResult = 1;
return data;
}
else
nRlt = 0;
}
catch
{
}
nResult = nRlt;
byte[] zeroary = new byte[0];
return zeroary;
}






JavaScriptを使用しています。