如何编写文件,然后将文件保存在文本fomat中 [英] how to write a file and then save a file in text fomat
本文介绍了如何编写文件,然后将文件保存在文本fomat中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在vb.net中创建一个Windows窗体..在这里我想写一个文本文件,写完后我必须保存该文件... plz帮我
i am creating a windows form in vb.net.. and in this i want to write a text file and after writing i have to save that file...plz help me
推荐答案
看看这里:
如何:阅读来自文件的文本 [ ^ ]
如何:将文本写入文件 [< a href =http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspxtarget =_ blanktitle =新窗口> ^ ]
Have a look here:
How to: Read Text from a File[^]
How to: Write Text to a File[^]
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string sData = "Hello Developer !";
//ANSWER 1:
using (FileStream fStream = File.Open(@"D:\MyFile.txt", FileMode.OpenOrCreate))
{
byte[] bt = Encoding.ASCII.GetBytes(sData);
fStream.Write(bt, 0, bt.Length);
fStream.Close();
}
//ANSWER 2 [Append In Existing Data]:
File.AppendAllText(@"D:\MyFile.txt", sData);
//ANSWER 3 [Fulsh Current Data An Write New One]:
File.WriteAllText(@"D:\MyFile.txt", sData);
}
}
}
这篇关于如何编写文件,然后将文件保存在文本fomat中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文