怎样用C#获取一个文件的大小
2个回答
展开全部
static void Main(string[] args){
const string fileName = "test.txt"; // 首先在bin目录建立一个test.txt文件
FileInfo f = new FileInfo(fileName);
long s1 = f.Length;
File.AppendAllText(fileName, "Hello.");
FileInfo f2 = new FileInfo(fileName);
long s2 = f2.Length;
long change = (s2 - s1)*2;
Console.WriteLine("文件大小:" + change.ToString()+"byte");
Console.ReadKey(true);
}
展开全部
使用 FileInfo ,添加引用IO,
OpenFileDialog op1 = new OpenFileDialog();
if (op1.ShowDialog() == DialogResult.OK)
{
FileInfo fi = new FileInfo(op1.FileName);
this.Text = (fi.Length/1024).ToString()+"kb";
}
OpenFileDialog op1 = new OpenFileDialog();
if (op1.ShowDialog() == DialogResult.OK)
{
FileInfo fi = new FileInfo(op1.FileName);
this.Text = (fi.Length/1024).ToString()+"kb";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询