Sabtu, 31 Desember 2011

baca tulis .ini or .txt file in .net


Imports System.IO


Public Class Form1

'''=======================

    Public Sub WriteContent(ByVal FullPath As String, _
    ByVal content As String)
         Dim fileWriter As StreamWriter
         Try
             fileWriter = New StreamWriter(FullPath)
             fileWriter.Write(content)
             fileWriter.Close()
         Catch x As Exception
             MsgBox(x.Message)
        End Try
     End Sub

    Public Function BacaBarisKe(ByVal FullPath As String, _
    ByVal baris As Integer)


        Dim fileReader As StreamReader


        Dim content As String = ""


        Dim i As Integer


        Try


            fileReader = New StreamReader(FullPath)


            For i = 1 To baris


                content = fileReader.ReadLine()


            Next
            fileReader.Close()


        Catch x As Exception


            MsgBox(x.Message)


        End Try


        Return content


    End Function
    Public Function BacaSeluruhFile(ByVal FullPath As String)


        Dim fileReader As StreamReader


        Dim content As String = ""


        Try


            fileReader = New StreamReader(FullPath)
            content = fileReader.ReadToEnd()


            fileReader.Close()


        Catch x As Exception


            MsgBox(x.Message)


        End Try


        Return content


    End Function


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As String
        a = BacaBarisKe("f:\cs.ini", 1)
    End Sub
End Class

Tidak ada komentar:

Posting Komentar