Windows Phone 7 中拷贝文件到独立存储

private void CopyToIsolatedStorage()
{
    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        string[] files = new string[] { "下雨天.mp3", "用心听.mp3", "我们的歌.mp3" };

        foreach (var _fileName in files)
        {
            if (!storage.FileExists(_fileName))
           {
               string _filePath = "Audio/" + _fileName;
               StreamResourceInfo resource = Application.GetResourceStream(new Uri(_filePath, UriKind.Relative));

                  using (IsolatedStorageFileStream file = storage.CreateFile(_fileName))
                 {
                          int chunkSize = 4096;
                        byte[] bytes = new byte[chunkSize];
                      int byteCount;

                     while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
                     {
                          file.Write(bytes, 0, byteCount);
                     }
                 }
           }
       }
    }
}

 

posted @ 2014-09-24 20:50  秋月光璇LMQ  阅读(159)  评论(0编辑  收藏  举报