VB.NET中 读取txt文件示例

                                VB.NET中 读取txt文件

1.所需命名空间

1
2
Imports System.IO
Imports System.Web

2. 读取文件代码

1
2
3
4
5
Dim fp As StreamReader
Dim s As String
fp = File.OpenText(HttpContext.Current.Server.MapPath(".\") & "Source.txt")
s = fp.ReadToEnd
fp.Close()

3. 文件示例

1
2
3
4
5
6
7
8
9
10
11
''SCRAP-INSTRUMENT BOV'',
''SCRAP-INSTRUMENT BOH'',
''SCRAP-INSTRUMENT BOA'',
''SCRAP-INSTRUMENT BOM'',
''SCRAP-ROTARY BOV'',
''SCRAP-ROTARY BOH'',
''SCRAP-ROTARY BOA'',
''SCRAP-ROTARY BOM'',
''SCRAP-S STEM BOV'',
''SCRAP-SPL PAINT BOH'',
''SCRAP- T26 BOH''

  文件内容被读取为字符串类型,可以直接当初字符串使用。如:

1
strBuilder.AppendLine(" AND MGD.Segment1 IN (" & s & ")')) MTORA")

 

posted @   scogee  阅读(15579)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示