01.
using
System;
02.
using
System.IO;
03.
using
System.Text;
04.
using
System.Windows.Forms;
05.
06.
namespace
text_input_all
07.
{
08.
class
Program
09.
{
10.
[STAThread]
11.
static
void
Main(
string
[] args)
12.
{
13.
14.
OpenFileDialog openFileDialog =
new
OpenFileDialog();
15.
openFileDialog.Filter =
"テキスト|*.txt|全て|*.*"
;
16.
openFileDialog.FilterIndex = 2;
17.
openFileDialog.InitialDirectory = @
"C:\"
;
18.
19.
if
(openFileDialog.ShowDialog() != DialogResult.OK)
20.
{
21.
return
;
22.
}
23.
24.
Console.WriteLine(openFileDialog.FileName);
25.
26.
string
path = openFileDialog.FileName;
27.
if
( File.Exists(path) )
28.
{
29.
Console.WriteLine($
"{path} は存在しています"
);
30.
}
31.
32.
33.
Encoding Enc = Encoding.GetEncoding(932);
34.
35.
try
36.
{
37.
using
(StreamReader ReadFile =
new
StreamReader(path, Enc))
38.
{
39.
40.
string
Text = ReadFile.ReadToEnd();
41.
42.
43.
ReadFile.Close();
44.
45.
Console.WriteLine(Text);
46.
}
47.
48.
}
49.
catch
(Exception ex)
50.
{
51.
Console.WriteLine(ex.Message);
52.
}
53.
54.
Console.ReadLine();
55.
}
56.
}
57.
}