如何查找文件中的字节数?

时间:2012-02-27 12:51:33

标签: c# file size byte

我在C#中申请。在这里,我想找出特定文件中的字节数。我在这里使用代码

using(FileStream fs=new FileStream(filename,FileMode.Open,FileAccess.Read))
{
    //Here i want to find the number of Bytes.
    //Some more code.
}

请帮帮我。谢谢。

2 个答案:

答案 0 :(得分:9)

您可以使用FileInfo类以字节为单位获取length(作为Int64):

new FileInfo(filename).Length;

答案 1 :(得分:6)

使用FileStream.Length属性。

  

获取流的字节长度。

相关问题