ファイル・フォルダ

ソースコード:

	/// <summary>
	/// ファイルはバイナリファイルであるかどうか
	/// </summary>
	/// <param name="filePath">パス</param>
	/// <returns>バイナリファイルの場合trueを返す</returns>
	public bool IsBinaryFile(string filePath)
	{
	    FileStream fs = File.OpenRead(filePath);
	    int len = (int)fs.Length;
	    int count = 0;
	    byte[] content = new byte[len];
	    int size = fs.Read(content, 0, len);

	    for (int i = 0; i < size; i++)
	    {
	        if (content[i] == 0)
	        {
	            count++;
	            if (count == 4)
	            {
	                return true;
	            }
	        }
	        else
	        {
	            count = 0;
	        }
	    }
	    return false;
	}
	/// <summary>
	/// ファイルはテキストファイルであるかどうか
	/// </summary>
	/// http://www.xuehi.com/
	/// <param name="filePath">パス</param>
	/// <returns>テキストファイルの場合Trueを返す</returns>
	public bool IsTextFile(string filePath)
	{
	    FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read);
	    byte[] byteData = new byte[1];
	    while (file.Read(byteData, 0, byteData.Length) > 0)
	    {
	        if (byteData[0] == 0)
	            return false;
	    }
	    return true;
	}


本当にほしかったのはこういうブログだったんだ

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結解除 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:33:20 (1600d)

PCpዾyǗlgĂ܂}WŔ܂z 萔O~ył񂫁z Yahoo yV NTT-X Store

z[y[W ̃NWbgJ[h COiq ӂ邳Ɣ[ COsیI COze