VB.NET中 读取txt文件示例
VB.NET中 读取txt文件
1.所需命名空间
Imports System.IO Imports System.Web
2. 读取文件代码
Dim fp As StreamReader
Dim s As String
fp = File.OpenText(HttpContext.Current.Server.MapPath(".\") & "Source.txt")
s = fp.ReadToEnd
fp.Close()
3. 文件示例
''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''
文件内容被读取为字符串类型,可以直接当初字符串使用。如:
strBuilder.AppendLine(" AND MGD.Segment1 IN (" & s & ")')) MTORA")
浙公网安备 33010602011771号