In: Computer Science
In this lab, you will learn to read data from a
sequential-access text file. To read data from a file, you need one
FileStream object and one StreamReader object. The StreamReader
object accepts the FileStream object as its argument.
To read data from a sequential-access text file, here's what you
need to do:
using System.IO;
/* Please see the source code */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StudentData
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs
e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.ShowDialog();
String file_name = openFileDialog1.FileName;
string text = File.ReadAllText(@file_name, Encoding.UTF8);
label1.Text = text;
}
}
}
/* See the editor screen*/
/* Output */
/* Output */
/* That's all. Thanks */
:)