using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace FileEx {
public partial class FileForm : Form {
//コンストラクタ
public FileForm() {
InitializeComponent();
}
//読み込みボタンのイベント処理
private void btnRead_Click(object sender, EventArgs e) {
StreamReader sr=null;
try {
sr=new StreamReader("My Documents\\test.txt");
tbText.Text=sr.ReadLine();
sr.Close();
} catch (Exception exc) {
if (sr!=null) sr.Close();
MessageBox.Show(exc.ToString(),"エラー");
}
}
//書き込みボタンのイベント処理
private void btnWrite_Click(object sender, EventArgs e) {
StreamWriter sw=null;
try {
sw=new StreamWriter("My Documents\\test.txt");
sw.WriteLine(tbText.Text);
sw.Close();
} catch (Exception exc) {
if (sw!=null) sw.Close();
MessageBox.Show(exc.ToString(),"エラー");
}
}
}
}
|