Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6021861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:46:29+00:00 2026-05-23T03:46:29+00:00

I can’t work out why is says that the file is open. Error is

  • 0

I can’t work out why is says that the file is open. Error is about half way through.

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:46:30+00:00Added an answer on May 23, 2026 at 3:46 am

    It says the file is in use because File.Create returns a stream object that you need to close/dispose of.

    From the documentation:

    Return Value

    Type: System.IO.FileStream
    A FileStream that provides read/write access to the file specified in path.

    At the very least, change every call to the method, such as these two:

    System.IO.File.Create(root + "\setting\world.txt")
    System.IO.File.Create(root + "\setting\levelseed.txt")
    

    To this:

    System.IO.File.Create(root + "\setting\world.txt").Dispose()
    System.IO.File.Create(root + "\setting\levelseed.txt").Dispose()
    

    Or, you can use a different method of the File class, File.WriteAllText:

    System.IO.File.WriteAllText(root + "\setting\world.txt", "")
    System.IO.File.WriteAllText(root + "\setting\levelseed.txt", "")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody point me to a resource that explains how to go about having
Can anyone recommend a fast way to sort the contents of a text file,
Can anyone help me trying to find out why this doesn't work. The brushes
Can you cast a List<int> to List<string> somehow? I know I could loop through
Can a LINQ enabled app run on a machine that only has the .NET
Can anyone recommend a good library for generating an audio file, such as mp3,
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) I have a Rails
Can I connect to a Ubuntu server, that is running MySQL using ADO.NET or
I need to solve the following question which i can't get to work by
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.