首先我们需要在SD卡读写文件的类型.例如txt,jpg,png等.当然,还可以自定义文件类型.方法如图:
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操作方法就一样了:
StorageFile textFile = await textFolder.CreateFileAsync("test.txt", CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(textFile, textWrite.Text,Windows.Storage.Streams.UnicodeEncoding.Utf8);
StorageFile textFile = await textFolder.GetFileAsync("test.txt"); textRead.Text = await FileIO.ReadTextAsync(textFile);
其效果如图.