天天看点

[C#]将数据存入硬盘文件(txt)

程序中已经得到一个string(也可以是byte[],需要进行编码),希望将它存入d:\1.txt 中

using system.io;

[C#]将数据存入硬盘文件(txt)
[C#]将数据存入硬盘文件(txt)

string path = @"d:\1.txt";//这是地址

string text = "这里是要写入的内容";

filestream fs = new filestream(path, filemode.create);

streamwriter sw = new streamwriter(fs, encoding.unicode);

sw.write(text);

sw.close();

fs.close();

[C#]将数据存入硬盘文件(txt)