如何获取文件流的长度 [英] how to get length of file stream

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

问题描述

我正在使用保存文件对话框保存文件..我想将该文件传递到文件流中..



System.IO.FileStream fs = (System.IO.FileStream)savedlg.OpenFile();

byte [] b =新字节[fs.length];



喜欢这种方式......

i希望找到fs的长度。我想把它传递给字节数组..



但是fs.lengh显示0....



如何获取文件流的原始长度

i''m saving a file using save file dialog..i want to pass that file into file stream..

System.IO.FileStream fs = (System.IO.FileStream)savedlg.OpenFile();
byte[] b=new byte[fs.length];

like this way...
i want to find the length of "fs". i want to pass it in to byte array..

but "fs.lengh" shows "0"....

how to get the original length of filestream

推荐答案

长度显示为零,因为长度 零。请参阅MSDN: SaveFileDialog.OpenFile方法 [ ^ ]



此方法创建一个具有所选名称的新文件,并使用读/写权限打开它。如果您选择现有文件,这可能会导致无意中丢失数据要在保留现有数据的同时将数据保存到现有文件,请使用File类使用FileName属性中返回的文件名打开文件。
The Length shows zero, because the length is zero. See MSDN: SaveFileDialog.OpenFile method[^]

"this method creates a new file with the selected name and opens it with read/write permissions. This can cause unintentional loss of data if you select an existing file to save to. To save data to an existing file while retaining existing data, use the File class to open the file using the file name returned in the FileName property."


参考以下链接..

它会帮助你..

http://msdn.microsoft.com/en-us/library/system.io.filestream.read.aspx [ ^ ]
refer below link..
it will help you..
http://msdn.microsoft.com/en-us/library/system.io.filestream.read.aspx[^]


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

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