AppDomain.CurrentDomain.BaseDirectory 它可以读取、也可以写入,而且是只用文件名,不用写文件的地址!下面我就把我写的例子贴上来: 首先我创建了一个 Windows应用程序 然后在界面如下:
我的代码是: //读取
private void button1_Click(object sender, EventArgs e)
{
if(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory+"123.txt") != "")
{
this.textBox1.Text = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "123.txt", Encoding.Default);
this.textBox3.Text = this.label3.Text + AppDomain.CurrentDomain.BaseDirectory + "123.txt";
}
}
//更改
private void button2_Click(object sender, EventArgs e)
{
if(File.Exists(AppDomain.CurrentDo