日期:2014-05-20 浏览次数:20862 次
IO using System.IO; String csdn="回帖是一种美德!每天回帖即可获得 10 分可用分!"; StreamWriter mysw=new StreamWriter(path); mysw.Write(csdn); mysw.Close();
------解决方案--------------------
换个变量名不行吗比如sw :)
------解决方案--------------------
private void Form1_Load(object sender, EventArgs e)
{
SaveFile("123123123",@"C:\1.txt");
}
public static void SaveFile(string p_Text, string p_Path)
{
System.IO.StreamWriter _StreamWriter = new System.IO.StreamWriter(p_Path);
_StreamWriter.Write(p_Text);
_StreamWriter.Close();
}
------解决方案--------------------
using System.IO;
namespace 将string变量保存到txt文档中
{
class Program
{
static void Main(string[] args)
{
string csdn="回帖是一种美德!每天回帖即可获得 10 分可用分!";
//使用Unicode编码,将csdn变量中的内容写到temp.txt文件中
StreamWriter sw = new StreamWriter("temp.txt", false, Encoding.Unicode);
sw.Write(csdn);
sw.Close();
Console.WriteLine("文件已经成功写入.");
Console.ReadLine();
}
}
}
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (StreamWriter sw = new StreamWriter(@"c:\1.txt", true)) //存在C:\1.txt里面
{
string a = "i belive i can fly";
sw.Write(a);
sw.Flush();
}
}
}
}