我一直在开发一款街机游戏,与每一款优秀的街机游戏一样,它都有一个内置的记分板,以便玩家可以看到谁得分更好。我的问题是,每次输入新的分数线时,它都会删除文本文件中所有先前的行。我一直在使用的代码如下:
If player1 > 25 Then
objReader.Close()
MsgBox("O " + jogador1 + " ganhou.")
tab1.Enabled = False
Dim wrtScore As String = "C:\Documents and Settings\Joao\My Documents\Visual Studio 2010\Projects\flaghunter\flaghunter\deposito\scores.txt"
Dim objWriter As New System.IO.StreamWriter(wrtScore)
wrtScore = wrtScore.Trim()
objWriter.WriteLine(jogador1 + " " + Str(player1))
objWriter.Close()
End If
感谢您的关注和任何帮助。
Use 文件.追加文本 http://msdn.microsoft.com/en-us/library/system.io.file.appendtext.aspx反而:
// This text is always added, making the file longer over time
// if it is not deleted.
Using sw As StreamWriter = File.AppendText(path)
sw.WriteLine("This")
sw.WriteLine("is Extra")
sw.WriteLine("Text")
End Using
如果第一次不存在,这将创建该文件;如果该文件已存在,则附加文本
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)