
//判空
private void button1_Click(object sender, EventArgs e)
{
if(openFileDialog.ShowDialog()!=DialogResult.OK)
return;
FileInfo file = new FileInfo(openFileDialog.FileName);
//把选择的文件路径显示在textBox中,不一定要
textBox1.Text = openFileDialog.FileName;
MessageBox.Show(file.Length==0?"空":"不空");
}
//写入
private void button2_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() != DialogResult.OK)
return;
FileInfo file = new FileInfo(openFileDialog.FileName);
StreamWriter writer = file.AppendText();
writer.Write("aaaaaaaaaaaaaaaaa");
//writer.Flush();
writer.Close();
}
{
//获取文件大小,以判断生成的文件是否有效
string m_Size = null;
FileInfo fi = new FileInfo(FilePath);
try {
m_Size = fi.Length.ToString;
} catch (Exception ex) {
m_Size = 0;
}
return m_Size;
}
private bool Boo_FileExist(string Str_File)//看文件是否存在
{
return System.IO.File.Exists(Str_File);
}
\\调用
if (Boo_FileExist(pFilePath) == 1 & Convert.ToInt32(GetFileSize(pFilePath)) >= 1) {
messagebox.show("存在");
}
这个函数您试了吗?怎么有那么多的错误啊?
没道理啊...都有哪些错误啊. 我的是正确的啊. 而且使用的都是系统类啊
能贴出来你的错误不呢
第二个按钮事件 可以直接把字符赋值给txt控件的文本