Skip to content

Instantly share code, notes, and snippets.

@d630
Created June 21, 2018 12:40
Show Gist options
  • Save d630/1de061409cd6c2339adad03abff7d632 to your computer and use it in GitHub Desktop.
Save d630/1de061409cd6c2339adad03abff7d632 to your computer and use it in GitHub Desktop.
Windows Forms: r/w file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Datei
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("test.dat", FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(textBox1.Text);
sw.Close();
fs.Close();
}
private void button2_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream("test.dat", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
textBox1.Text = "";
while (sr.Peek() != -1)
{
textBox1.AppendText(sr.ReadLine() + Environment.NewLine);
}
sr.Close();
fs.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment