IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    WP8.1开发:SD卡读写特定类型文件

    编程小梦发表于 2014-10-13 04:50:40
    love 0

    首先我们需要在SD卡读写文件的类型.例如txt,jpg,png等.当然,还可以自定义文件类型.方法如图:

    首先我们先获取SD卡文件夹并在其中建立我们自己的文件夹:

    var devices = Windows.Storage.KnownFolders.RemovableDevices;
                var sdCards = await devices.GetFoldersAsync();
                if (sdCards.Count == 0) return;
                StorageFolder firstCard = sdCards[0];
                textFolder = await firstCard.CreateFolderAsync("text", CreationCollisionOption.OpenIfExists);

    当我们在SD卡建立文件后,其操作就和正常的 StorageFolder操作方法就一样了:

    向SD卡写文件:

    StorageFile textFile = await textFolder.CreateFileAsync("test.txt", CreationCollisionOption.ReplaceExisting);
    
               await  FileIO.WriteTextAsync(textFile, textWrite.Text,Windows.Storage.Streams.UnicodeEncoding.Utf8);

    向SD卡读文件:

    StorageFile textFile = await textFolder.GetFileAsync("test.txt");
                textRead.Text = await FileIO.ReadTextAsync(textFile);

    其效果如图.

    如果小梦的文章对你有帮助!欢迎支持小梦!



沪ICP备19023445号-2号
友情链接