如何找到文件的大小 [英] How to find the size of a file

查看:65
本文介绍了如何找到文件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家又来了一个问题.我在DB中有一个文件名,当我显示名称时,我必须显示文件名+文件大小.文件路径在我的项目本身内部.因此,如何从路径获取文件大小,以便可以显示具有名称和大小的文件...



说文件名是Img.jpg,大小是5kb,我必须像这样显示 Img.jpg(5kb)

Hi guys am back with another question.. I have a file name in DB and when i display the name i must show the filename+ size of it. The file path is inside my project itself.. So how can i get the filesize from the path so that i can display the file with name and as size...



Say the filename is Img.jpg and size is 5kb i must show like this Img.jpg(5kb)

推荐答案

使用可以使用System.IO.FileInfo的 length 属性来获取文件的大小.
use System.IO.FileInfo and length property of it to get size of file.


您可以使用FileInfo.Length.它以字节为单位给出文件大小.

You can use FileInfo.Length. It gives file size in bytes.

FileInfo fileInfo = new FileInfo("Input.txt");
Console.Write(string.Format("{0} ({1}B)", fileInfo.Name, fileInfo.Length));


有关文件大小,请使用 FileInfo.Length属性 [ ^ ].

通常有关常见的I/O任务 [
For file size use the FileInfo.Length Property[^].

More information generally on Common I/O Tasks[^].


这篇关于如何找到文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆