【问题标题】:How to write byte array to StorageFile in WindowsPhone 8如何在 WindowsPhone 8 中将字节数组写入 StorageFile
【发布时间】:2013-10-30 14:31:52
【问题描述】:

我搜索并找到了这个,但它不适用于 Windows Phone 8,并且仅适用于 Windows 应用商店应用:

http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileio.writebytesasync

我如何在 WP8 中做到这一点?

【问题讨论】:

    标签: windows-phone-8 bytearray storagefile


    【解决方案1】:

    您可以使用二进制编写器:

    byte[] buffer;   
    
    using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
    {
    
      using (IsolatedStorageFileStream FS = new IsolatedStorageFileStream(fileName, FileMode.Create, ISF))
      {
        using (BinaryWriter BW = new BinaryWriter(FS))
        {
          BW.Write(buffer, 0, buffer.Lenght);
        }
      }
    }
    

    或者像@KooKiz 所说的让它更简单:

    using (IsolatedStorageFileStream FS = new IsolatedStorageFileStream(fileName, FileMode.Create, ISF))
     {
         FS.Write(buffer, 0, buffer.Lenght);    
     }
    

    【讨论】:

    • 为什么要使用 BinaryWriter? fs.Write(buffer, 0, buffer.Length);
    • 如果在第二行定义了 ISF。
    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    • 2012-04-10
    • 2012-05-14
    • 2015-09-04
    相关资源
    最近更新 更多