向書本學(xué)習(xí),還要向?qū)嵺`學(xué)習(xí)、向生活學(xué)習(xí)。消化已有知識(shí),
而且要力求有所發(fā)現(xiàn)、有所發(fā)明、有所創(chuàng)造
2019/3/24 8:18:11
文件的建立
源代碼:
private void Button1_Click(object sender, System.EventArgs e)
{
//string wenjian;
//wenjian = filename.Text;
if (this.filename.Text.ToString().Trim()=="")
{
this.body.Text = "********";
}
else
{
try
{
string thisfilename=filename.Text.ToString();
FileStream fsMyfile = new FileStream(thisfilename,FileMode.Create,FileAccess.ReadWrite);
fsMyfile.Close();
this.body.Text = "********";
}
catch
{
//Console.WriteLine("{0} Second exception caught.", e);
this.body.Text = "********";
}
}
}
文件的刪除
源代碼:
private void Button4_Click(object sender, System.EventArgs e)
{
if (this.filename.Text.ToString().Trim()=="")
{
this.body.Text = "********";
}
else
{
try
{
string thisfilename=filename.Text.ToString();
File.Delete(thisfilename);
this.body.Text = "********";
}
catch
{
//Console.WriteLine("{0} Second exception caught.", e);
this.body.Text = "********";
}
}
}
文件的讀取
源代碼:
private void Button2_Click(object sender, System.EventArgs e)
{
if (this.filename.Text.ToString().Trim()=="")
{
this.body.Text = "請(qǐng)選擇文件名稱!";
}
else
{
try
{
string thisfilename=filename.Text.ToString();
StreamReader srMyfile = new StreamReader(thisfilename);
srMyfile.BaseStream.Seek(0,SeekOrigin.Begin);
string sl;
sl = srMyfile.ReadToEnd();
this.body.Text = sl;
srMyfile.Close();
}
catch
{
//Console.WriteLine("{0} Second exception caught.", e);
this.body.Text = "此文件不存在!";
}
}
}
文件的寫入
源代碼:
private void Button3_Click(object sender, System.EventArgs e)
{
if (this.filename.Text.ToString().Trim()=="")
{
this.body.Text = "********";
}
else
{
try
{
string thisfilename=filename.Text.ToString();
StreamWriter swMyfile = new StreamWriter(thisfilename);
string xieru = body.Text.ToString();
swMyfile.WriteLine(xieru);
swMyfile.Flush();
swMyfile.Close();
this.body.Text = "********";
}
catch
{
//Console.WriteLine("{0} Second exception caught.", e);
this.body.Text = "********";
}
}
深圳市南山區(qū)南山街道南海大道西桂廟路北陽光華藝大廈1棟4F、4G-04
咨詢電話:136 8237 6272
大客戶咨詢:139 0290 5075
業(yè)務(wù)QQ:195006118
技術(shù)QQ:179981967
客戶案列
新聞資訊
資質(zhì)榮譽(yù)
團(tuán)隊(duì)風(fēng)采
項(xiàng)目進(jìn)度查詢
售前QQ咨詢
QQ溝通 項(xiàng)目QQ溝通