File.Open opens a FileStream on the specified path, with mode setting and sharing option. : File « 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 » FileScreenshots 
File.Open opens a FileStream on the specified path, with mode setting and sharing option.
 

Imports System
Imports System.IO
Imports System.Text

Public Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"
        Dim fs As FileStream
        If File.Exists(path= False Then
            fs = File.Create(path)
            Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")
            fs.Write(info, 0, info.Length)
            fs.Close()
        End If
        fs = File.Open(path, FileMode.Open, FileAccess.Read)
        Dim b(1024As Byte
        Dim temp As UTF8Encoding = New UTF8Encoding(True)

        Do While fs.Read(b, 0, b.Length0
            Console.WriteLine(temp.GetString(b))
        Loop
        Try
            Dim fs2 As FileStream = File.Open(path, FileMode.Open)
            fs2.Close()
        Catch As Exception
            Console.Write("Opening the file twice is disallowed.")
            Console.WriteLine(", as expected: {0}", e.ToString())
        End Try
        fs.Close()
    End Sub
End Class

   
  
Related examples in the same category
1.Delete *.Bak under a directoryDelete *.Bak under a directory
2.Change file attribute for *.*
3.Get Files under an Directory and print its Full Name and LengthGet Files under an Directory and print its Full Name and Length
4.Find Hidden File under a directoryFind Hidden File under a directory
5.Update file create time, last access time and last write timeUpdate file create time, last access time and last write time
6.Get Invalid File Name CharsGet Invalid File Name Chars
7.Delete a file if exist
8.Is it a File or a DirectoryIs it a File or a Directory
9.File Time: created, last modified and accessedFile Time: created, last modified and accessed
10.File Information
11.English File Size
12.File Class Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects.
13.File Class provides static methods for the creation, copying, deletion, moving, and opening of files
14.Open path in string to read
15.Create Text file with File.CreateText
16.File.AppendAllLines (String, IEnumerable(String)) appends lines to a file, and then closes the file.
17.File.AppendAllText opens a file, appends string to the file, and then closes the file.
18.File.AppendAllText appends string to the file, creating the file if it does not already exist.
19.File.AppendText creates a StreamWriter that appends UTF-8 encoded text to an existing file.
20.File.Copy copies an file to a new file.
21.File.Create creates or overwrites a file in the specified path.
22.File.Create creates or overwrites the specified file.
23.File.CreateText creates or opens a file for writing UTF-8 encoded text.
24.File.Decrypt decrypts a file that was encrypted using the Encrypt method.
25.File.Exists determines whether the specified file exists.
26.File.GetAccessControl gets a FileSecurity object that encapsulates the access control list (ACL) entries
27.File.GetAttributes gets the FileAttributes of the file on the path.
28.File.GetCreationTime returns the creation date and time of the specified file or directory.
29.File.GetLastAccessTime returns the date and time the specified file or directory was last accessed.
30.File.GetLastWriteTime returns the date and time the specified file or directory was last written to.
31.File.Move moves a specified file to a new location, providing the option to specify a new file name.
32.File.Open opens a FileStream on the specified path with read/write access.
33.File.Open opens a FileStream on the specified path, with the specified mode and access.
34.File.OpenRead opens an existing file for reading.
35.File.OpenText opens an existing UTF-8 encoded text file for reading.
36.File.OpenWrite opens an existing file or creates a new file for writing.
37.File.ReadAllLines opens a text file, reads all lines of the file, and then closes the file.
38.File.ReadAllLines opens a file, reads all lines of the file with the specified encoding, and then closes the file.
39.File.ReadLines reads the lines of a file.
40.Use Linq to search and read files
41.File.Replace replaces the contents with the contents of another file
42.File.SetLastAccessTime sets the date and time the specified file was last accessed.
43.File.SetLastWriteTime sets the date and time that the specified file was last written to.
44.File.Exists Method tests whether the specified file exists.
45.File.GetAttributes Gets the FileAttributes of the file on the path.
www_.j_a__va___2___s___._com__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.