-
Notifications
You must be signed in to change notification settings - Fork 10
/
Program.cs
65 lines (54 loc) · 1.89 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.IO;
namespace LargeFileSearch
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入要查询的文件全路径");
start:
string path = Console.ReadLine();
if (!File.Exists(path))
{
Console.WriteLine("文件不存在,请重新输入要查询的文件全路径");
goto start;
}
while (true)
{
Console.WriteLine("请输入要查询的关键字");
start2:
string search = Console.ReadLine();
if (string.IsNullOrEmpty(search))
{
Console.WriteLine("关键字不能为空,请重新输入关键字");
goto start2;
}
using (FileStream fs = new FileStream(path, FileMode.Open))
{
using (StreamReader r = new StreamReader(fs))
{
Console.WriteLine("开始时间:" + DateTime.Now.ToString("HH:mm:ss"));
string s = null;
do
{
try
{
s = r.ReadLine();
if (s != null && s.Contains(search))
{
Console.WriteLine(s);
}
}
catch (Exception)
{
}
} while (s != null);
Console.WriteLine("全部查询完成");
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
}
}
}
}
}
}