请问怎样使用C#中的filessize?有个例子更佳!!

解决方案 »

  1.   

    If you want to get the file's size , you can use FileInfo.Length;
    for instance:// The following example displays the names and sizes
    // of the files in the specified directory.
    using System;
    using System.IO;public class FileLength
    {
        public static void Main()
        {
            // Make a reference to a directory.
            DirectoryInfo di = new DirectoryInfo("c:\\");
            // Get a reference to each file in that directory.
            FileInfo[] fiArr = di.GetFiles();
            // Display the names and sizes of the files.
            Console.WriteLine("The directory {0} contains the following files:", di.Name);
            foreach (FileInfo f in fiArr)
                Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length);
        }
    }
      

  2.   

    谢谢回复!f.Length可以得出文件的大小,但是是以byte来算的;filesize是按kb来算的!能不能介绍一下filesize的用法?