SlideShare una empresa de Scribd logo
1 de 5
Chapter five
Manipulating Files (File handling)
Introduction
 Most applications require data to be stored in files
 Spreadsheets
 Word processing
 etc
 File - is a collection of data stored in a disk with a specific name and a directory path.
 When a file is opened for reading or writing, it becomes a stream.
 Stream - is basically the sequence of bytes passing through the communication path.
There are two main streams: input and output stream.
 Input stream - used for reading data/byte stream from file (read operation) and
 Output stream - used for writing data/byte stream into the file (write operation).
 input and output stream objects are created from class FileStream
System.IO Namespace
File Manipulation Activities
 Open a file, reading a file, writing a file, appending a text to a file, copying a file, moving a
file, and Deleting a file.
 The System.IO namespace has various classes that are used for performing
various operations with files, like creating and deleting files, reading from or writing
to a file, closing a file, etc.
The followingtable shows some commonly used non-abstract classes in the
System.IO namespace:
FileStream Class
 FileStream class in System.IO namespace helps in reading from, writing to & closing files.
 You need to create a FileStream object to create a new file or open an existing file.
Syntax:
FileStream <object_name> = new FileStream( <file_name>,
<FileMode Enumerator>, <FileAccess Enumerator>, <FileShare Enumerator>);
Or
Dim <object_name> As FileStream = New FileStream(<file_name>, <FileMode
Enumerator>, <FileAccess Enumerator>, <FileShare Enumerator>)
I/O Class Description
BinaryReader Reads primitive data from a binary stream.
BinaryWriter Writes primitive data in binary format.
BufferedStream A temporary storage for a stream of bytes.
Directory Helps in manipulating a directory structure.
DirectoryInfo Used for performing operations on directories.
DriveInfo Provides information for the drives.
File Helps in manipulating files.
FileInfo Used for performing operations on files.
FileStream Used to read from and write to any location in a
file.
MemoryStream Used for random access of streamed data stored
in memory.
Path Performs operations on path information.
StreamReader Used for reading characters from a byte stream.
StreamWriter Is used for writing characters to a stream.
StringReader Is used for reading from a string buffer.
StringWriter Is used for writing into a string buffer.
For example, for creating a FileStream object F for reading a file named sample.txt:
FileStream F = new FileStream("sample.txt", FileMode.Open, FileAccess.Read,
FileShare.Read);
Or
Dim f1 As FileStream = New FileStream("test.dat", FileMode.OpenOrCreate,
FileAccess.ReadWrite)
Parameter Description
FileMode The FileMode enumerator defines
various methods for opening files. The
members of the FileMode enumerator
are:
Append: It opens an existing file and puts cursor at the end of file, or creates
the file, if the file does not exist.
Create: It creates a new file.
CreateNew:It specifies to the operating system that it should create a new
file.
Open: It opens an existing file.
OpenOrCreate:It specifies to the operating system that it should open a file if
it exists, otherwise it should create a new file.
Truncate: It opens an existing file and truncates its size to zero bytes.
FileAccess FileAccess enumerators have
members: Read, ReadWrite,
and Write.
FileShare FileShare enumerators have the
following members:
Inheritable: It allows a file handle to
pass inheritance to the child
processes
None: It declines sharing of the
current file
Read: It allows opening the file for
reading
ReadWrite: It allows opening the file
for reading and writing
Write: It allows opening the file for
writing
Example 1:- Program to create a new file in the D Drive:-
C#.net
static void Main(){
FileStream fs = new FileStream("d:createfileusingC#.txt", FileMode.Append,
FileAccess.Write);// String path = ("D:test1.txt");
StreamWriter sw = new StreamWriter(fs);
Console.WriteLine("File Created");
Console.WriteLine("Enter the text which you want to write to the file");
string str = Console.ReadLine();
VB.net
Sub Main()
Dim s As System.IO.Stream
s = System.IO.File.Open("d: createfileusingvb.txt", System.IO.FileMode.Create)
Console.WriteLine("File Created")
Console.ReadLine()
s.Close()
End Sub
}
Example2:- Programto Write data into a File
VB.net
Sub Main()
Dim s As System.IO.Stream
s = System.IO.File.Open("d:createusingvb.txt", System.IO.FileMode.Open,
System.IO.FileAccess.Write)
Dim I As Integer
For I = 0 To 10
s.WriteByte(CByte(I))
Next
Console.WriteLine("Data Entered")
s.Close()
Console.ReadLine()
Example3:Programto Readdata from a File
C# .net
static void Main(string[] args)
{
String path = @"D: createusingvb.txt ";//"d: createusingvb.txt",
String[] lines;
lines = File.ReadAllLines(path);
Console.WriteLine(lines[0]);
// Console.WriteLine(lines[1]);
Console.ReadKey();} }
VB.net
Sub Main()
Dim s As System.IO.Stream
s = System.IO.File.Open("d: createusingvb.txt", System.IO.FileMode.Open,
System.IO.FileAccess.Read)
Dim I As Integer
For I = 0 To 10
Console.WriteLine("{0}", s.ReadByte())
Next
Console.WriteLine("Data Ended")
s.Close()
Console.ReadLine() End Sub
Example 4 program to copy file
C#.net
static void Main(){
String path = @"D: createfileusingC#.txt"; // ("D:wow.txt");
String copypath = @"D:copyofcreatefileusingC#.txt";
Console.WriteLine("Coped");
File.Copy(path, copypath);
Console.ReadKey();}}
Example 5 Program to Delete a File
C#.net
static void Main()
{
String path = ("D: createfileusingC#.txt");//String path = @"D:test1.txt";
Console.WriteLine("The file is deleted");
File.Delete(path);
Console.ReadKey();
}
VB.net
Sub Main()
System.IO.File.Delete("d:  createfileusingC#.txt")
Console.WriteLine("File deleted")
Console.ReadLine()
End Sub

Más contenido relacionado

La actualidad más candente

File Handling
File HandlingFile Handling
File HandlingWaqar Ali
 
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary fileCBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary fileShivaniJayaprakash1
 
File system interface
File system interfaceFile system interface
File system interfaceDayan Ahmed
 
Data file handling in python reading & writing methods
Data file handling in python reading & writing methodsData file handling in python reading & writing methods
Data file handling in python reading & writing methodskeeeerty
 
Data file operations in C++ Base
Data file operations in C++ BaseData file operations in C++ Base
Data file operations in C++ BasearJun_M
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3Ala Qunaibi
 
Degonto file management
Degonto file managementDegonto file management
Degonto file managementDegonto Islam
 
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Filesprimeteacher32
 
Data file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing filesData file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing fileskeeeerty
 

La actualidad más candente (18)

File Handling
File HandlingFile Handling
File Handling
 
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary fileCBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
CBSE - Class 12 - Ch -5 -File Handling , access mode,CSV , Binary file
 
File system interface
File system interfaceFile system interface
File system interface
 
File Management
File ManagementFile Management
File Management
 
C# File IO Operations
C# File IO OperationsC# File IO Operations
C# File IO Operations
 
Data file handling in python reading & writing methods
Data file handling in python reading & writing methodsData file handling in python reading & writing methods
Data file handling in python reading & writing methods
 
Data file operations in C++ Base
Data file operations in C++ BaseData file operations in C++ Base
Data file operations in C++ Base
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3
 
File Management
File ManagementFile Management
File Management
 
Degonto file management
Degonto file managementDegonto file management
Degonto file management
 
File handling
File handlingFile handling
File handling
 
File structures
File structuresFile structures
File structures
 
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Files
 
Handling computer files
Handling computer filesHandling computer files
Handling computer files
 
File organization
File organizationFile organization
File organization
 
File Management
File ManagementFile Management
File Management
 
Data file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing filesData file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing files
 
File organization
File organizationFile organization
File organization
 

Similar a Switching & Multiplexing

File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingChereLemma2
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentationAzeemaj101
 
Learn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems pptLearn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems pptgeethasenthil2706
 
FIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxFIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxAshwini Raut
 
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSFILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSVenugopalavarma Raja
 
Is2215 lecture6 lecturer_file_access
Is2215 lecture6 lecturer_file_accessIs2215 lecture6 lecturer_file_access
Is2215 lecture6 lecturer_file_accessdannygriff1
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfstudy material
 
ASP.NET Session 7
ASP.NET Session 7ASP.NET Session 7
ASP.NET Session 7Sisir Ghosh
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
 
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugevsol7206
 

Similar a Switching & Multiplexing (20)

File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ Programming
 
Data file handling
Data file handlingData file handling
Data file handling
 
File Handling in Java Oop presentation
File Handling in Java Oop presentationFile Handling in Java Oop presentation
File Handling in Java Oop presentation
 
Learn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems pptLearn about the File Concept in operating systems ppt
Learn about the File Concept in operating systems ppt
 
FIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptxFIle Handling and dictionaries.pptx
FIle Handling and dictionaries.pptx
 
pspp-rsk.pptx
pspp-rsk.pptxpspp-rsk.pptx
pspp-rsk.pptx
 
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSFILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
 
Is2215 lecture6 lecturer_file_access
Is2215 lecture6 lecturer_file_accessIs2215 lecture6 lecturer_file_access
Is2215 lecture6 lecturer_file_access
 
File Handling
File HandlingFile Handling
File Handling
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
 
Files in c++
Files in c++Files in c++
Files in c++
 
FILE MANAGEMENT.pptx
FILE MANAGEMENT.pptxFILE MANAGEMENT.pptx
FILE MANAGEMENT.pptx
 
Filepointers1 1215104829397318-9
Filepointers1 1215104829397318-9Filepointers1 1215104829397318-9
Filepointers1 1215104829397318-9
 
ASP.NET Session 7
ASP.NET Session 7ASP.NET Session 7
ASP.NET Session 7
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
 
Intake 38 10
Intake 38 10Intake 38 10
Intake 38 10
 
Python-files
Python-filesPython-files
Python-files
 

Más de MelkamuEndale1

new Call for Innovation Competition - Registration Form (2).docx
new Call for Innovation Competition - Registration Form (2).docxnew Call for Innovation Competition - Registration Form (2).docx
new Call for Innovation Competition - Registration Form (2).docxMelkamuEndale1
 

Más de MelkamuEndale1 (6)

lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
lecture 6.pptx
lecture 6.pptxlecture 6.pptx
lecture 6.pptx
 
lecture 4.pptx
lecture 4.pptxlecture 4.pptx
lecture 4.pptx
 
lecture 7.pptx
lecture 7.pptxlecture 7.pptx
lecture 7.pptx
 
lecture 1.pptx
lecture 1.pptxlecture 1.pptx
lecture 1.pptx
 
new Call for Innovation Competition - Registration Form (2).docx
new Call for Innovation Competition - Registration Form (2).docxnew Call for Innovation Competition - Registration Form (2).docx
new Call for Innovation Competition - Registration Form (2).docx
 

Último

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Switching & Multiplexing

  • 1. Chapter five Manipulating Files (File handling) Introduction  Most applications require data to be stored in files  Spreadsheets  Word processing  etc  File - is a collection of data stored in a disk with a specific name and a directory path.  When a file is opened for reading or writing, it becomes a stream.  Stream - is basically the sequence of bytes passing through the communication path. There are two main streams: input and output stream.  Input stream - used for reading data/byte stream from file (read operation) and  Output stream - used for writing data/byte stream into the file (write operation).  input and output stream objects are created from class FileStream System.IO Namespace
  • 2. File Manipulation Activities  Open a file, reading a file, writing a file, appending a text to a file, copying a file, moving a file, and Deleting a file.  The System.IO namespace has various classes that are used for performing various operations with files, like creating and deleting files, reading from or writing to a file, closing a file, etc. The followingtable shows some commonly used non-abstract classes in the System.IO namespace: FileStream Class  FileStream class in System.IO namespace helps in reading from, writing to & closing files.  You need to create a FileStream object to create a new file or open an existing file. Syntax: FileStream <object_name> = new FileStream( <file_name>, <FileMode Enumerator>, <FileAccess Enumerator>, <FileShare Enumerator>); Or Dim <object_name> As FileStream = New FileStream(<file_name>, <FileMode Enumerator>, <FileAccess Enumerator>, <FileShare Enumerator>) I/O Class Description BinaryReader Reads primitive data from a binary stream. BinaryWriter Writes primitive data in binary format. BufferedStream A temporary storage for a stream of bytes. Directory Helps in manipulating a directory structure. DirectoryInfo Used for performing operations on directories. DriveInfo Provides information for the drives. File Helps in manipulating files. FileInfo Used for performing operations on files. FileStream Used to read from and write to any location in a file. MemoryStream Used for random access of streamed data stored in memory. Path Performs operations on path information. StreamReader Used for reading characters from a byte stream. StreamWriter Is used for writing characters to a stream. StringReader Is used for reading from a string buffer. StringWriter Is used for writing into a string buffer.
  • 3. For example, for creating a FileStream object F for reading a file named sample.txt: FileStream F = new FileStream("sample.txt", FileMode.Open, FileAccess.Read, FileShare.Read); Or Dim f1 As FileStream = New FileStream("test.dat", FileMode.OpenOrCreate, FileAccess.ReadWrite) Parameter Description FileMode The FileMode enumerator defines various methods for opening files. The members of the FileMode enumerator are: Append: It opens an existing file and puts cursor at the end of file, or creates the file, if the file does not exist. Create: It creates a new file. CreateNew:It specifies to the operating system that it should create a new file. Open: It opens an existing file. OpenOrCreate:It specifies to the operating system that it should open a file if it exists, otherwise it should create a new file. Truncate: It opens an existing file and truncates its size to zero bytes. FileAccess FileAccess enumerators have members: Read, ReadWrite, and Write. FileShare FileShare enumerators have the following members: Inheritable: It allows a file handle to pass inheritance to the child processes None: It declines sharing of the current file Read: It allows opening the file for reading ReadWrite: It allows opening the file for reading and writing Write: It allows opening the file for writing
  • 4. Example 1:- Program to create a new file in the D Drive:- C#.net static void Main(){ FileStream fs = new FileStream("d:createfileusingC#.txt", FileMode.Append, FileAccess.Write);// String path = ("D:test1.txt"); StreamWriter sw = new StreamWriter(fs); Console.WriteLine("File Created"); Console.WriteLine("Enter the text which you want to write to the file"); string str = Console.ReadLine(); VB.net Sub Main() Dim s As System.IO.Stream s = System.IO.File.Open("d: createfileusingvb.txt", System.IO.FileMode.Create) Console.WriteLine("File Created") Console.ReadLine() s.Close() End Sub } Example2:- Programto Write data into a File VB.net Sub Main() Dim s As System.IO.Stream s = System.IO.File.Open("d:createusingvb.txt", System.IO.FileMode.Open, System.IO.FileAccess.Write) Dim I As Integer For I = 0 To 10 s.WriteByte(CByte(I)) Next Console.WriteLine("Data Entered") s.Close() Console.ReadLine() Example3:Programto Readdata from a File C# .net static void Main(string[] args) { String path = @"D: createusingvb.txt ";//"d: createusingvb.txt", String[] lines; lines = File.ReadAllLines(path); Console.WriteLine(lines[0]); // Console.WriteLine(lines[1]); Console.ReadKey();} } VB.net Sub Main() Dim s As System.IO.Stream s = System.IO.File.Open("d: createusingvb.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read) Dim I As Integer For I = 0 To 10 Console.WriteLine("{0}", s.ReadByte()) Next Console.WriteLine("Data Ended") s.Close()
  • 5. Console.ReadLine() End Sub Example 4 program to copy file C#.net static void Main(){ String path = @"D: createfileusingC#.txt"; // ("D:wow.txt"); String copypath = @"D:copyofcreatefileusingC#.txt"; Console.WriteLine("Coped"); File.Copy(path, copypath); Console.ReadKey();}} Example 5 Program to Delete a File C#.net static void Main() { String path = ("D: createfileusingC#.txt");//String path = @"D:test1.txt"; Console.WriteLine("The file is deleted"); File.Delete(path); Console.ReadKey(); } VB.net Sub Main() System.IO.File.Delete("d: createfileusingC#.txt") Console.WriteLine("File deleted") Console.ReadLine() End Sub