none
要存入檔案無法存取該檔案。 RRS feed

  • 問題

  • Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim r As Integer
            Dim pf_name As String = ""
            Dim f_name As String = ""
            r = MsgBox("是否確定轉郵局格式", MsgBoxStyle.OkCancel, "學期平均")
            If r = 1 Then
                Dim file_name As String = "學期成績.txt"
                Me.SaveFileDialog1.Filter = "*.txt|text|*.txt|(*.txt)"
                Me.SaveFileDialog1.FilterIndex = 2
                Me.SaveFileDialog1.DefaultExt = ".txt"
                Me.SaveFileDialog1.FileName = file_name
                Try
                    If Me.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                        Dim mythread As New System.Threading.Thread(AddressOf job)

                        pf_name = Me.SaveFileDialog1.FileName
                        LG_File_Path_Full = pf_name
                        Me.Label6.Text = LG_File_Path_Full
                        f_name = IO.Path.GetFileNameWithoutExtension(pf_name)
                        Me.LBL_std_count.Text = "人數:" & "資料讀取中...請稍候.."
                        mythread.Start()

                    End If
                Catch ex As Exception

                End Try
            End If

        End Sub
        Public Sub job()

            Dim FileStream As IO.FileStream = IO.File.Open(LG_File_Path_Full, FileMode.Create)

     

            Dim myStreamWriter As IO.StreamWriter = New StreamWriter(LG_File_Path_Full, True, System.Text.Encoding.Default)

            Dim StrTextLine As String = ""
            strTextLine = "h"
            strTextLine = strTextLine & "DB"
            strTextLine = strTextLine & "把檔案寫入進去"
            myStreamWriter.WriteLine(StrTextLine)
            myStreamWriter.Flush()
            myStreamWriter.Close()

            MsgBox("轉檔完畢")

        End Sub
    由於另一個處理序正在使用檔案 'C:\Documents and Settings\paa18699\桌面\學期成績.txt',所以無法存取該檔案
    我想把我所寫的檔案存入進去但是無法存入
    請大家幫幫忙
    謝謝

    2009年12月10日 上午 08:32

解答

  •         Dim myStreamWriter As IO.StreamWriter = New StreamWriter(LG_File_Path_Full, True, System.Text.Encoding.Default)


    改成這樣
    Dim myStreamWriter As IO.StreamWriter = New StreamWriter(fileStream)
    • 已標示為解答 ㄎㄎ 2009年12月10日 上午 09:15
    2009年12月10日 上午 09:05