Programming - Part 4
Programming - Part 4
FILE HANDLING
File handling in VB.NET refers to the process of reading, writing, and manipulating
files using Visual Basic programming language.
It involves various operations such as creating, opening, reading, writing, closing, and
deleting files.
File System Object (FSO): Provides methods for creating, deleting, and moving files and
folders.
Stream Classes: Represent a sequence of bytes, enabling reading and writing operations
on files.
Input/Output (I/O) Classes: Facilitate various file operations, such as StreamReader for
reading text files and StreamWriter for writing text files.
Opening Files: Use File.Open or File.OpenRead methods to open existing files for
reading or writing.
Reading Files: Use StreamReader class to read text files line by line or byte by byte.
Writing Files: Use StreamWriter class to write text files line by line or byte by byte.
Deleting Files: Use File.Delete method to remove files from the system.
Copying and Moving Files: Use File.Copy and File.Move methods to copy or move files
between locations.
File Information Access: Use FileInfo and DirectoryInfo classes to retrieve file and
directory information, such as size, creation date, and attributes.
Creating a file
To create a new file you can use the file.create method.
For example the following code creates a new file called myfile.txt in the
current directory
Writing to file
To write a file use the writeline method of the streamwriter object.
For example the following code writes the string “welcome to A level computer
experts” to the file we created above.
The streamReader class provides methods for reading lines of text from file.
For example the following code reads the contents of the file myfile.txt and prints
them to console.
Do while line=file.Readline()
Console.Writeline(line)
Loop
File.close()
Closing a File
It is very important(zvakakosha) to close a file after you have finished using it.
This will release file handle and allow other programs to access the file.
The close method of the streamreader and streamwriter classes closes the file.
file.Close()
Imports System.Text
Imports System
Module Module1
Sub Main()
'creating a file
'writing to file
'closing file
file.Close()
End Sub
End Module
CIPHERS
Are a type of encryption algorithm that utilizes string operations to transform
plaintext into ciphertext and vice versa.
newChar = character
Else
End If
ciphertext &= newChar
Next character
Return ciphertext
End Function
'to decrypt
newChar = character
Else
End If
Next character
Return plaintext
End Function
Contact: 0781081816
Email:[email protected]
ISAIAH 43 VS 2