问题描述
我正在使用VB 2101 Express,我试图纠正该程序,但它不会超出循环的结尾,有人知道为什么吗?
If (Not System.IO.Directory.Exists(root + \"\\setting\")) Then
System.IO.Directory.CreateDirectory(root + \"\\setting\")
End If
\'loads world settings
If File.Exists(root + \"\\setting\\world.txt\") Then
Dim ioFile As New StreamReader(root + \"\\setting\\world.txt\")
Dim ioLine As String \' Going to hold one line at a time
Dim ioLines As String \' Going to hold whole file
ioLine = ioFile.ReadLine
ioLines = ioLine
Do
ioLine = ioFile.ReadLine
ioLines = ioLines & vbCrLf & ioLine
cmbworld.Items.Add(ioLine)
Loop Until ioLine = \"\" \'***<--- IT STOPS HERE!***
Else
System.IO.File.Create(root + \"\\setting\\world.txt\")
End If
解决方法
这不是更简单吗?
For Each line As String In File.ReadLines(\"root + \"\\setting\\world.txt\"\")
If line.Length <> 0 Then
cmbworld.Items.Add(line)
End If
Next line
MSDN:File.ReadLines方法(字符串)
, 尝试将最后一行设置为Loop Until ioLine is nothing