我想从FileInfo
得到一个字节[]。无法从FileStream写
在这里,FileInfo
(fi)是我放入我的silverlight应用程序的文件。
因此,在MSND如发现,我这样做:
byte[] b = new byte[fi.Length];
UTF8Encoding temp = new UTF8Encoding(true);
//Open the stream and read it back.
using (FileStream fs = fi.OpenRead())
{
while (fs.Read(b, 0, b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
但是,这样做,它的保护级别,我不能使用此。
所以,我这样做:
byte[] b = new byte[fi.Length];
UTF8Encoding temp = new UTF8Encoding(true);
//Open the stream and read it back.
using (FileStream fs = fi.OpenRead())
{
while (fs.Read(b, 0, b.Length) > 0)
{
fs.Write(b, 0, b.Length);
}
}
但我得到了我不能从FileStream
编写信息。
为什么我不能写我的文件我放入我的应用程序到一个字节? 当文件被删除时,它成为一个FileInfo。
为什么我用OpenRead()
?因为在msdn上,它似乎正在写入文件:here
OpenWrite()
也会出现访问错误。
有没有另外一种方法可以让yy FileInfo文件变成一个字节?
因此,您只是为阅读打开流,但试图写入它......您还期望什么 - “无法写入R/O流”似乎对我来说是合理的行为...不是确定你想要整体做什么 - 所以你可能有其他的想法 - 考虑增加你的实际目标的问题。 – 2014-09-25 07:42:36
看:'fs = fi.OpenRead()','fs'打开读取,而不是写入 – 2014-09-25 07:42:48
@AlexeiLevenkov我想要的是,将File I drop(转换成FileInfo)写入一个字节。 – 2014-09-25 07:45:52