sábado, 4 de enero de 2014

3.Leer un archivo de texto (txt) completo


        Dim oFile As System.IO.File
        Dim oRead As System.IO.StreamReader
        Dim EntireFile As String


        oRead = File.OpenText("C:\WINDOWS\security\Wlag.Neg")
        EntireFile = oRead.ReadToEnd()
        MsgBox(EntireFile)

En este espacio va lo que desees hacer con la variable ya declarada y llena.
Para otras funciones como eliminar el archivo utilizamos esto, para cerrar el archivo y evitar que se nos denegué el acceso.

        oRead.Close()

Otro modo seria:




   Dim BaseDato1 = "C:\Server1.txt"
        Try
            Dim SPath As String = (BaseDato1)
            Dim sContent As String = vbNullString

            With My.Computer.FileSystem
                ' verifica si existe el path  
                If .FileExists(SPath) Then
                    ' lee todo el contenido  
                    sContent = .ReadAllText(SPath)
                    MsgBox(sContent.ToString, MsgBoxStyle.Information, "Datos")
                Else
                    MsgBox("ruta inválida", MsgBoxStyle.Critical, "error")
                End If
            End With
            ' errores  
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Critical)
        End Try


No hay comentarios:

Publicar un comentario

Error al montar disco duro en Linux

¿Te ha ocurrido frecuentemente este error al intentar montar un disco duro en tu sistema Linux? A mi me sucede mucho y note qu...