c#中如何保存文件呢?

mayanmajesty 2008-03-03 04:57:12
我会打开文件,就是用openFileDialog显示对话框,选择打开路径.然后用streamreader读入!
我不知道保存文件要如何操作,也是用openFileDialog显示对话框,选择保存路径.然后用streamwriter读入吗!
...全文
615 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
peterchao1254 2011-12-14
  • 打赏
  • 举报
回复
学习中,正好不会。
wjhere 2010-09-16
  • 打赏
  • 举报
回复
学习学习
mayanmajesty 2008-03-03
  • 打赏
  • 举报
回复
谢谢
csrwgs 2008-03-03
  • 打赏
  • 举报
回复
1楼没错
保存分2种
(1)FileStream,对应的是Byte【】
(2)StreamWriter,对应 的是Stream
北京的雾霾天 2008-03-03
  • 打赏
  • 举报
回复
下面的代码示例演示如何使用 WriteAllText 方法在文件中写入文本。在此示例中,如果文件尚不存在,则创建一个文件,并向其中添加文本。


using System;
using System.IO;
using System.Text;

class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";

// This text is added only once to the file.
if (!File.Exists(path))
{
// Create a file to write to.
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(path, createText, Encoding.UTF8);
}

// This text is always added, making the file longer over time
// if it is not deleted.
string appendText = "This is extra text" + Environment.NewLine;
File.AppendAllText(path, appendText, Encoding.UTF8);

// Open the file to read from.
string readText = File.ReadAllText(path, Encoding.UTF8);
Console.WriteLine(readText);
}
}
goddy123 2008-03-03
  • 打赏
  • 举报
回复
SaveFileDialog

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧