我需要一次寫入大量文本到文件,但它必須以特定的方式格式化,而不是全部在一行中。如何將多行文本一次寫入文件?
我的代碼是:
If System.IO.File.Exists(filepath) Then
Using reader As StreamReader = New StreamReader(filepath)
sLine = reader.ReadToEnd
End Using
Using writer As StreamWriter = New StreamWriter(filepath)
writer.Write("[HealthBarSettings]
MaxHealthTicks = 50
MaxHealthMicroTicks = 100
DefaultHealthPerMicroTick = 50
DefaultHealthPerTick = 200
DefaultHealthPerMegaTick = 1000
TickAlpha = 200
MicroTickAlpha = 140
MicroTickHeight = 0.5
MegaTickAlpha = 255
TickThickness = 1.0
MicroTickThickness = 1.0
MegaTickThickness = 2.0
UseCompression = 1
GoTransparent = 1
[GeneralDataHero]()
FadeTimerForHealthBar = 2.0
ZeroHealthAlpha = 225
FullHealthAlpha = 200
DefaultChampionCollisionRadius = 65.0")
End Using
MsgBox("File Written")
Else
MsgBox("File does not exist")
End If
但是,這並不工作,因爲它不會使用所有的文字,只是使用 「[HealthBarSettings]」,並自動停止報價之後。
我希望創建一個StringBuilder對象......所有值追加到它,然後喂該stringbuilder對象作家。 – highwingers
[將多行寫入使用Visual Basic的文本文件]可能的重複(http://stackoverflow.com/questions/14903938/write-mutiple-lines-to-a-text-file-using-visual-basic) –