Output:
Code:
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 Question_4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
FileStream fs;
StreamReader sr;
StreamWriter sw;
//For read
private void button1_Click(object sender, EventArgs e)
{
fs = new FileStream("File.txt", FileMode.Open);
sr = new StreamReader(fs);
Object ob;
ob = sr.ReadLine();
textBox1.Text = ob.ToString();
sr.Close();
fs.Close();
}
//For write
private void button2_Click(object sender, EventArgs e)
{
fs = new FileStream("File.txt", FileMode.Create);
sw = new StreamWriter(fs);
sw.WriteLine(textBox1.Text);
sw.Close();
fs.Close();
}
//For clear
private void button3_Click(object sender, EventArgs e)
{
textBox1.Clear();
}
}
}
No comments:
Post a Comment