Create FileInfo class : FileInfo « File Directory « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » File Directory » FileInfoScreenshots 
Create FileInfo class
 

Imports System
Imports System.IO

Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\MyTest.txt"
        Dim fi1 As FileInfo = New FileInfo(path)
        If fi1.Exists = False Then
            Dim sw As StreamWriter = fi1.CreateText()
            sw.WriteLine("A")
            sw.WriteLine("B")
            sw.WriteLine("C")
            sw.Flush()
            sw.Close()
        End If
        Dim sr As StreamReader = fi1.OpenText()
        Do While sr.Peek() >= 0
            Console.WriteLine(sr.ReadLine())
        Loop
        Try
            Dim path2 As String = path + "temp"
            Dim fi2 As FileInfo = New FileInfo(path2)
            fi2.Delete()
            fi1.CopyTo(path2)
            Console.WriteLine("{0} was copied to {1}.", path, path2)
            fi2.Delete()
            Console.WriteLine("{0} was successfully deleted.", path2)
        Catch As Exception
            Console.WriteLine("The process failed: {0}", e.ToString())
        End Try
    End Sub
End Class

   
  
Related examples in the same category
1.FileInfo Class provides properties and instance methods for the creation, copying, deletion, moving, and opening of files
2.FileInfo provides properties and instance methods for the creation, copying, deletion, moving, and opening of files
3.Use FileInfo.AppendText to create StreamWriter and add text to it
4.FileInfo.CopyTo copies a file
5.Use FileInfo open a file to read
6.FileInfo.CopyTo (String, Boolean) copies a file, allowing the overwriting of an existing file.
7.FileInfo.Create
8.FileInfo.CreateText creates a StreamWriter that writes a new text file.
9.FileInfo.Decrypt decrypts a file that was encrypted using the Encrypt method.
10.FileInfo.Delete deletes a file.
11.FileInfo.Directory Property gets an instance of the parent directory.
12.FileInfo.DirectoryName Property gets a string representing the directory's full path.
13.FileInfo.GetAccessControl gets a FileSecurity object that encapsulates the access control list (ACL) entries
14.FileInfo.IsReadOnly Property gets or sets a value that determines if the current file is read only.
15.FileInfo.Length Property gets the size, in bytes, of the current file.
16.FileInfo.Name Property gets the name of the file.
17.FileInfo.Open opens a file in the specified mode.
18.FileInfo.Open (FileMode, FileAccess) opens a file in the specified mode with read, write, or read/write access.
19.FileInfo.Open with settings for File Read Write Mode, File Access Mode, File Share Mode
20.FileInfo.OpenRead creates a read-only FileStream.
21.FileInfo.OpenText creates a StreamReader with UTF8 encoding that reads from an existing text file.
22.FileInfo.OpenWrite creates a write-only FileStream.
23.FileInfo.Replace replaces the contents of a file
24.FileSystemInfo Class provides the base class for both FileInfo and DirectoryInfo objects.
25.FileInfo.Length Property tells the size, in bytes, of the current file.
w__w___w__.___j_av__a__2s_.c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.