using System.IO using (StreamWriter sw = new StreamWriter("TestFile.txt")) { // Add some text to the file. sw.Write("This is the "); sw.WriteLine("header for the file."); sw.WriteLine("-------------------"); // Arbitrary objects can also be written to the file. sw.Write("The date is: "); sw.WriteLine(DateTime.Now); }
using System; using System.IO; public class TextToFile { private const string FILE_NAME = "MyFile.txt"; public static void Main(String[] args) { if (File.Exists(FILE_NAME)) { return; } StreamWriter sr = File.CreateText(FILE_NAME); sr.WriteLine ("字符串"); sr.Close(); } }
using System; using System.IO; public class TextToFile { private const string FILE_NAME = "MyFile.txt"; public static void Main(String[] args) { if (File.Exists(FILE_NAME)) { return; } StreamWriter sr = File.CreateText(FILE_NAME); sr.WriteLine ("字符串"); sr.Close(); } }
好像不是text to file 是richTextBox中显示的所有数据saveto file,一次就把所有数据存入事先建立好的文件(dd.txt)中。不知是否说明白。
thank u everybody已经找到例子private void button4_Click(object sender, System.EventArgs e)
//public void SaveMyFile() { // Create a SaveFileDialog to request a path and file name to save to. SaveFileDialog saveFile1 = new SaveFileDialog();// Initialize the SaveFileDialog to specify the RTF extension for the file. saveFile1.DefaultExt = "*.txt"; saveFile1.Filter = "TXT Files|*.txt";// Determine if the user selected a file name from the saveFileDialog. if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&saveFile1.FileName.Length > 0) { // Save the contents of the RichTextBox into the file.
using (StreamWriter sw = new StreamWriter("TestFile.txt"))
{
// Add some text to the file.
sw.Write("This is the ");
sw.WriteLine("header for the file.");
sw.WriteLine("-------------------");
// Arbitrary objects can also be written to the file.
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
}
using System.IO;
public class TextToFile {
private const string FILE_NAME = "MyFile.txt";
public static void Main(String[] args) {
if (File.Exists(FILE_NAME)) {
return;
}
StreamWriter sr = File.CreateText(FILE_NAME);
sr.WriteLine ("字符串");
sr.Close();
}
}
\viewkind4\uc1\pard\lang2052\f0\fs18\'ca\'fd\'be\'dd\'b1\'a3\par
}
using System.IO;
public class TextToFile {
private const string FILE_NAME = "MyFile.txt";
public static void Main(String[] args) {
if (File.Exists(FILE_NAME)) {
return;
}
StreamWriter sr = File.CreateText(FILE_NAME);
sr.WriteLine ("字符串");
sr.Close();
}
}
是richTextBox中显示的所有数据saveto file,一次就把所有数据存入事先建立好的文件(dd.txt)中。不知是否说明白。
//public void SaveMyFile()
{
// Create a SaveFileDialog to request a path and file name to save to.
SaveFileDialog saveFile1 = new SaveFileDialog();// Initialize the SaveFileDialog to specify the RTF extension for the file.
saveFile1.DefaultExt = "*.txt";
saveFile1.Filter = "TXT Files|*.txt";// Determine if the user selected a file name from the saveFileDialog.
if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&&saveFile1.FileName.Length > 0)
{
// Save the contents of the RichTextBox into the file.
richTextBox1.SaveFile saveFile1.FileName,RichTextBoxStreamType.PlainText);
}
}