using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ReadLine
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog OFD = new OpenFileDialog())
{
try
{
OFD.Filter = "文字檔(*.txt)|*.txt";
OFD.ShowDialog();
textBox1.Text = OFD.FileName;
StreamReader SReader = new StreamReader(textBox1.Text, Encoding.Default);
textBox2.Text = SReader.ReadLine();
SReader.Close();
}
catch
{
}
}
}
private void button2_Click(object sender, EventArgs e)
{
using (SaveFileDialog SFD = new SaveFileDialog())
{
try
{
SFD.Filter = "文字檔(*.txt)|*.txt";
SFD.ShowDialog();
textBox3.Text = SFD.FileName;
StreamWriter SWriter = new StreamWriter(textBox3.Text);
SWriter.WriteLine(textBox2.Text);
}
catch
{
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
還蠻聰明,遇到已經存在的檔名會自動跳出提示”是否取代”!
留言列表