110,569
社区成员
发帖
与我相关
我的任务
分享
TStringList *sl = new TStringList;
sl->Add("123456789");
sl->SaveToFile("D:\info.txt");
delete sl;
#include <stdio.h>
FILE* pfile;
pfile = fopen("c:\\test.txt", "a+");
fprintf(pfile, "%s\n", "我测试");
fclose(pfile);
OpenFileDialog1.Filter = "文本文件(*.txt)|*.txt"
Me.txtRead.Multiline = True
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Me.txtRead.Text = System.IO.File.ReadAllText(OpenFileDialog1.FileName, System.Text.Encoding.GetEncoding("gb2312"))
End If
using System;
using System.IO;
class Test
{
public static void Main()
{
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
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);
}
}
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SaveFileDialog1.Filter = "*.txt|*.txt"
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
System.IO.File.AppendAllText(SaveFileDialog1.FileName, Me.TextBox1.Text, System.Text.Encoding.GetEncoding("gb2312"))'如果要覆盖原有文件内容,就把AppendAllText换成WriteAllText
End If
End Sub