- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不知道为什么说文件已打开。错误大约进行了一半。
Dim worldWriter As New System.IO.StreamWriter(cmbworldsave) (this is the line that i am having trouble with)
Imports System.IO
Imports System.Text
Public Class frmindex
'Variables
Dim vcmbworld As ComboBox
Dim addworld As String
Dim root As String
Dim hellworld As String
Dim pvp As String
Dim whitelist As String
Dim spawnmonsters As String
Dim onlinemode As String
Dim spawnanimals As String
Dim bit As String
Private Sub frmindex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If cmbserverapplication.Text = "Jar File" Then
lblram.Visible = True
txbram.Visible = True
Else
lblram.Visible = False
txbram.Visible = False
End If
'Set Default Root
root = CurDir()
'finds load files
txbroot.Text = root
'Checks if save folder exists if not creates one
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
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
End If
'loads ip
If File.Exists(root + "\setting\ip.txt") Then
For Each line As String In File.ReadLines(root + "\setting\ip.txt")
If line.Length <> 0 Then
cmbip.Items.Add(line)
End If
Next line
End If
'loads levelseed
If File.Exists(root + "\setting\levelseed.txt") Then
For Each line As String In File.ReadLines(root + "\setting\levelseed.txt")
If line.Length <> 0 Then
cmblevelseed.Items.Add(line)
End If
Next line
End If
txbseverport.Text = My.Settings.sseverport
txbmaxplayers.Text = My.Settings.smaxplayers
txbspawnprotection.Text = My.Settings.sspawnprotection
txbroot.Text = My.Settings.sroot
cmbworld.Text = My.Settings.sworld
cmbip.Text = My.Settings.sseverip
cmblevelseed.Text = My.Settings.slevelseed
cmbserverapplication.Text = My.Settings.sseverapplication
txbram.text = My.Settings.sram
hellworld = My.Settings.shellworld
pvp = My.Settings.spvp
whitelist = My.Settings.swhitelist
spawnmonsters = My.Settings.sspawnmonsters
onlinemode = My.Settings.sonlinemode
spawnanimals = My.Settings.sspawnanimals
cbxhellworld.Checked = hellworld
cbxpvp.Checked = pvp
cbxwhitelist.Checked = whitelist
cbxspawnmonsters.Checked = spawnmonsters
cbxonlinemode.Checked = onlinemode
cbxspawnanimals.Checked = spawnanimals
End Sub
Private Sub btnrootbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnrootbwse.Click
' Creates a FolderBrowserDialog object
Dim fbdroot As New FolderBrowserDialog
'Dialog
With fbdroot
' Desktop is the root folder in the dialog.
.RootFolder = Environment.SpecialFolder.Desktop
' Select the C:\Windows directory on entry.
.SelectedPath = CurDir()
' Prompt the user with a custom message.
.Description = "Please Select Root Of Sever"
root = .SelectedPath
If .ShowDialog = DialogResult.OK Then
root = .SelectedPath
txbroot.Text = root
End If
End With
End Sub
Private Sub btnbwsworld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnworld.Click
If Not cmbworld.Text = "" Then
cmbworld.Items.Add(cmbworld.Text)
cmbworld.Text = ""
End If
End Sub
Private Sub btnaddip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddip.Click
If Not cmbip.Text = "" Then
cmbip.Items.Add(cmbip.Text)
cmbip.Text = ""
End If
End Sub
Private Sub btnlaunch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlaunch.Click
If System.IO.Directory.Exists(root + "\setting") = True Then
Else
System.IO.Directory.CreateDirectory(root + "\setting")
End If
Dim sbcmbworld As New StringBuilder()
For Each item As Object In cmbworld.Items
sbcmbworld.AppendFormat("{0} {1}", item, Environment.NewLine)
Next
Dim cmbworldsave As String = root + "\setting\world.txt"
If System.IO.File.Exists(cmbworldsave) = True Then
Else
System.IO.File.Create(root + "\setting\world.txt")
End If
Dim worldWriter As New System.IO.StreamWriter(cmbworldsave) **<---- ERROR HERE!**
worldWriter.Write(sbcmbworld.ToString()) 'Use the stringbuilder here
worldWriter.WriteLine()
worldWriter.Close()
Dim sbcmbip As New StringBuilder()
For Each item As Object In cmbworld.Items
sbcmbip.AppendFormat("{0} {1}", item, Environment.NewLine)
Next
Dim cmbipsave As String = root + "\setting\ip.txt"
If System.IO.File.Exists(cmbworldsave) = True Then
Else
System.IO.File.Create(root + "\setting\ip.txt")
End If
Dim ipwriter As New System.IO.StreamWriter(cmbipsave)
ipwriter.Write(sbcmbip.ToString()) 'Use the stringbuilder here
ipwriter.WriteLine()
ipwriter.Close()
Dim sbcmblevelseed As New StringBuilder()
For Each item As Object In cmbworld.Items
sbcmbip.AppendFormat("{0} {1}", item, Environment.NewLine)
Next
Dim cmblevelseedsave As String = root + "\setting\levelseed.txt"
If System.IO.File.Exists(cmbworldsave) = True Then
Else
System.IO.File.Create(root + "\setting\levelseed.txt")
End If
Dim levelseedWriter As New System.IO.StreamWriter(cmbipsave)
levelseedWriter.Write(sbcmblevelseed.ToString()) 'Use the stringbuilder here
levelseedWriter.WriteLine()
levelseedWriter.Close()
If cbxhellworld.Checked Then
hellworld = "true"
Else
hellworld = "false"
End If
If cbxpvp.Checked Then
pvp = "true"
Else
pvp = "false"
End If
If cbxwhitelist.Checked Then
whitelist = "true"
Else
whitelist = "false"
End If
If cbxspawnmonsters.Checked Then
spawnmonsters = "true"
Else
spawnmonsters = "false"
End If
If cbxonlinemode.Checked Then
onlinemode = "true"
Else
onlinemode = "false"
End If
If cbxspawnanimals.Checked Then
spawnanimals = "true"
Else
spawnanimals = "false"
End If
My.Settings.sseverport = txbseverport.Text
My.Settings.smaxplayers = txbmaxplayers.Text
My.Settings.sspawnprotection = txbspawnprotection.Text
My.Settings.sroot = txbroot.Text
My.Settings.sworld = cmbworld.Text
My.Settings.sseverip = cmbip.Text
My.Settings.slevelseed = cmblevelseed.Text
My.Settings.sseverapplication = cmbserverapplication.Text
My.Settings.sram = txbram.text
My.Settings.shellworld = hellworld
My.Settings.spvp = pvp
My.Settings.swhitelist = whitelist
My.Settings.sspawnmonsters = spawnmonsters
My.Settings.sonlinemode = onlinemode
My.Settings.sspawnanimals = spawnanimals
My.Settings.Save()
If System.IO.File.Exists(root + "\server.properties") = True Then
Else
System.IO.File.Create(root + "\server.properties")
End If
Dim propertyWriter As New System.IO.StreamWriter(root + "\server.properties")
propertyWriter.Write("level-name=" + cmbworld.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("hellworld=" + hellworld)
propertyWriter.Write("spawn-monsters=" + spawnmonsters)
propertyWriter.WriteLine("")
propertyWriter.Write("online-mode=" + onlinemode)
propertyWriter.WriteLine("")
propertyWriter.Write("max-players=" + txbmaxplayers.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("server-ip=" + cmbip.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("pvp=" + pvp)
propertyWriter.WriteLine("")
propertyWriter.Write("level-speed=" + cmblevelseed.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("sever-port=" + txbseverport.Text)
propertyWriter.WriteLine("")
propertyWriter.Write("spawn-monsters=" + spawnmonsters)
propertyWriter.WriteLine("")
propertyWriter.Close()
Dim serverpath As String
If cmbserverapplication.Text = "Jar File" Then
If System.IO.File.Exists(root + "\minecraft_server.jar") = True Then
If Environment.Is64BitOperatingSystem = True Then
bit = "64"
Else
bit = "32"
End If
serverpath = root + "\minecraft_server.jar"
Dim javapath As String
Dim launchcode As String
If bit = 64 Then
javapath = "C:\Program Files (x86)\Java\jre6\bin\java"
Else
javapath = "C:\Program Files\Java\jre6\bin\java"
End If
launchcode = "-Xmx" + txbram.Text + "M -Xms" + txbram.Text + "M -jar " + serverpath + " nogui"
Dim pi As New ProcessStartInfo(javapath)
pi.Arguments = launchcode
Process.Start(pi)
Else
MsgBox("The server file does not exist. Please make sure that you have select the right file type and that it has not been renamed.")
End If
Else
If System.IO.File.Exists(root + "\minecraft_server.exe") = True Then
serverpath = root + "\minecraft_server.exe"
Dim startInfo As System.Diagnostics.ProcessStartInfo
Dim pStart As New System.Diagnostics.Process
startInfo = New System.Diagnostics.ProcessStartInfo(serverpath)
pStart.StartInfo = startInfo
pStart.Start()
Else
MsgBox("The server file does not exist. Please make sure that you have select the right file type and that it has not been renamed.")
End If
End If
End Sub
Private Sub btnremoveworld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremoveworld.Click
cmbworld.Items.RemoveAt(cmbworld.SelectedIndex)
End Sub
Private Sub btnremoveip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremoveip.Click
cmbip.Items.RemoveAt(cmbip.SelectedIndex)
End Sub
Private Sub btnaddlevelseed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddlevelseed.Click
cmblevelseed.Items.Add(cmblevelseed.Text)
cmblevelseed.Text = ""
End Sub
Private Sub btnremovelevelseed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnremovelevelseed.Click
cmblevelseed.Items.RemoveAt(cmblevelseed.SelectedIndex)
End Sub
Private Sub cmbserverapplication_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbserverapplication.SelectedIndexChanged
If cmbserverapplication.Text = "Jar File" Then
lblram.Visible = True
txbram.Visible = True
Else
lblram.Visible = False
txbram.Visible = False
End If
End Sub
End Class
最佳答案
它说文件正在使用中,因为 File.Create返回您需要关闭/处理的流对象。
来自 documentation :
Return Value
Type: System.IO.FileStream
A FileStream that provides read/write access to the file specified in path.
System.IO.File.Create(root + "\setting\world.txt")
System.IO.File.Create(root + "\setting\levelseed.txt")
System.IO.File.Create(root + "\setting\world.txt").Dispose()
System.IO.File.Create(root + "\setting\levelseed.txt").Dispose()
System.IO.File.WriteAllText(root + "\setting\world.txt", "")
System.IO.File.WriteAllText(root + "\setting\levelseed.txt", "")
关于vb.net - 为什么它说文件正在使用VB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6370833/
我正在编写一个 JS 程序,我有一个条件可以根据输入进行一些算术运算。如果我遇到操作类型为“add”,我需要将两个值相加;如果我得到“times”作为我的运算符值,我需要相乘。 我尝试使用基本的 if
我正在编写一个仅作为查看器的应用程序 - 无需创建、无需编辑、无需保存。 显然,那么,不会有自动保存,但是还有什么其他东西可以从 autosavesInPlace 返回 YES 改变世界,从而对观看者
Azure 开始出现以下错误: Unsupported token. Unable to initialize the authorization context. 每当我尝试更改我的应用程序时,我都
当我编写 out.println() 时,Eclipse 提示 out 无法解析。 我导入了 java.io.* 和其他 servlet 包。 最佳答案 只是在黑暗中拍摄,我认为这就是您正在寻找的出路
Azure 开始出现以下错误: Unsupported token. Unable to initialize the authorization context. 每当我尝试更改我的应用程序时,我都
是否可以执行类似的操作来检查 radio 表单是否未选中: if !($(this).find("input:checked")) {} 正确的语法是什么? 最佳答案 试试这个: $(this).fi
我正在尝试从表中选择行,其中 date 列值等于澳大利亚悉尼的当前日期 (UTC+10h)。服务器位于悉尼,因此我想使用 SYSDATETIME()。这是我的查询: SELECT * FROM dat
我听说 JavaScript 实际上并不像其他语言那样“指向”内存中的值(或对象,因为在 JS 中一切都是对象)。相反,JS 变量引用内存中的其他值/对象。这是真的?指向和引用之间的语义区别是什么?
我的计算机科学类(class)有一项作业,其中要求读取包含多个测试分数的文件,并要求我对它们进行求和并求平均值。虽然求和和求平均值很容易,但我在读取文件时遇到问题。老师说用这个语法 Scanner s
Java 的 XML 解析器似乎认为我的 XML 文档在根元素之后的格式不正确。但我已经用几种工具验证了它,但他们都不同意。这可能是我的代码错误,而不是文档本身的错误。如果你们能给我提供任何帮助,我将
根据这份文件: http://www.stroustrup.com/terminology.pdf l 值具有同一性且不可移动。 公关值是可移动的,但没有身份。 x 值具有同一性并且是可移动的。 关于
这个问题在这里已经有了答案: What does "atomic" mean in programming? (7 个答案) 关闭 5 年前。 我正在阅读 MongoDB 的 documentati
在 PHP 和 MySQL 中有没有一种方法能够比较 2 个不同的数组(列表)变量并说出有多少项是相同的 例如, $array1 = "hello, bye, google, laptop, yes"
本文来自 Effective Java Programs that use the int enum pattern are brittle. Because int enums are compil
C++ 中有一些特性是类型安全的,而另一些则不是。 C++ 类型安全示例: char c = 'a'; int *p = &c; // this is not allowed (compiler
我有一个 CS 课的作业,它说要读取一个包含多个测试分数的文件,并要求我对它们求和并取平均值。虽然求和和平均很容易,但我在读取文件时遇到了问题。老师说要用这个语法 Scanner scores = n
嗯.. 有时,PyDev 会说“ Unresolved 导入错误”。 在我的环境中 Python2.6.6 Eclipse3.7 PyDev2.2.2 错误是。 > Unresolved import
我正在向服务器发送请求,服务器正在处理请求并做出响应。但是在我的应用程序中,我收到了: Error Domain=NSURLErrorDomain Code=-1017 "cannot parse r
在我最近的一次讨论中,有人告诉我这样说是不正确的,因为 Ajax 已经是 Javascript。 上下文: “我如何在网页中 blablababal,这样它就不必刷新页面” 我的回答: “使用 Jav
下午好。 我一直在尝试使用 ffmpeg 将 .mpeg 拆分为一系列 .jpeg 图像。请注意,这是指定 here 的逆问题,但我面临的问题与该线程的作者面临的问题不同。 具体来说,我已经在我的 f
我是一名优秀的程序员,十分优秀!