我的目标是将“文本框”输入保存到文本文件,然后能够将保存的文本从同一文本文件加载回文本框.有帮助吗?我认为我的一个错误是在控制台上阅读……namespace aaa{public partial class MainPage : PhoneApplication...

我的目标是将“文本框”输入保存到文本文件,然后能够将保存的文本从同一文本文件加载回文本框.有帮助吗?
我认为我的一个错误是在控制台上阅读……
namespace aaa
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string fileName = "test.txt";
FileStream fs = null;
fs = new FileStream(fileName, FileMode.CreateNew);
StreamWriter writer = new StreamWriter(fs);
writer.Write(textBox1.Text);
}
private void btnWrite_Click(object sender, RoutedEventArgs e)
{
}
private void btnRead_Click(object sender, RoutedEventArgs e)
{
public static void Main()
{
using (StreamReader sr = new StreamReader("test.txt"))
{
string line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
}
}
}
解决方法:
在Windows Phone运行时和Windows Phone Silverlight应用程序中使用Windows.Storage.StorageFile.
在Working with data and files部分的MSDN文档中有一些示例.特别参见Quickstart: Local app data或Quickstart: Roaming app data和Quickstart: Reading and writing files
最后一个快速入门直接在阅读和编写短文本片段到文件时进行演示:
// Create sample file; replace if exists.
StorageFolder folder =
Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile sampleFile =
await folder.CreateFileAsync("test.txt", CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteTextAsync(sampleFile, textBox1.text);
织梦狗教程
本文标题为:c# – 在文本文件Windows Phone 8.1上读取和写入


基础教程推荐
猜你喜欢
- C#中 Json 序列化去掉null值的方法 2022-11-18
- C#调用摄像头实现拍照功能的示例代码 2023-03-09
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- 实例详解C#实现http不同方法的请求 2022-12-26
- C# 解析XML和反序列化的示例 2023-04-14
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- C#中的Linq to JSON操作详解 2023-06-08
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- Unity shader实现高斯模糊效果 2023-01-16