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

Dan*_*any 3 c# size byte file

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

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

请帮帮我.谢谢.

Yuc*_*uck 10

您可以使用FileInfo该类以字节为单位获取其长度(作为Int64):

new FileInfo(filename).Length;
Run Code Online (Sandbox Code Playgroud)


Ani*_*Ani 6

使用该FileStream.Length属性.

获取流的长度(以字节为单位).