SlideShare a Scribd company logo
1 of 12
Application on File Program
Session 8
Objectives
 Typically example of file read & write
 Simple File Handling Program
 Several Home work
Typical example of file read & write
try
{
FileStream aFile = new FileStream("Log.txt",
FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(aFile);
bool truth = true // Write data to file.
sw.WriteLine("Hello to you.");
sw.WriteLine("It is now {0} and things are looking
good.“,DateTime.Now.ToLongDateString());
sw.Write("More than that,");
sw.Write(" it’s {0} that C# is fun.", truth);
sw.Close();
}
catch (IOException ee)
{
Console.WriteLine("An IO exception has been
thrown!");
Console.WriteLine(ee.ToString());
Console.ReadLine();
return;
}
• Go to the application directory and find the Log.txt
file. It is located in the binDebug folder because you
used a relative path.
• The WriteLine() method writes the string passed to
it, followed immediately by a newline character.
• You can see in the example that this causes the next
write operation to begin on a new line.
• The Write() method simply writes the string passed
to it to the file, without a newline character appended.
• Two sentence is in one line.
The StreamReader Object
• try
• {
• FileStream aFile = new FileStream("Log.txt", FileMode.Open);
• StreamReader sr = new StreamReader(aFile);
• line = sr.ReadLine();
• // Read data in line by line.
• while(line != null)
• {
• Console.WriteLine(line);
• line = sr.ReadLine();
• }
• sr.Close();
• }
• catch(IOException e)
• {
• Console.WriteLine("An IO exception has been thrown!");
• Console.WriteLine(e.ToString());
• return;
• }
• Console.ReadKey();
 ReadLine() method to read text from the file.
 This method reads text until a new line is found,and returns
the resulting text as a string.
 The method returns a null when the end of the file has been
reached, which you use to test for the end of the file.
 Note that you use a while loop, which ensures that the line
read isn’t null before any code in the body of the loop is
executed.
Simple File Handling Program
String line,k="";
StreamReader sr = new
StreamReader("E:trainingreadsample.txt");
StreamWriter sw = new
StreamWriter("E:trainingWritesample.txt");
line = sr.ReadLine();
while (line != null)
{
k += line;
line = sr.ReadLine();
}
sw.WriteLine(k);
sw.Close();
sr.Dispose();
Direct using streamReader & streamWriter
Input :
readsample.txt Contain
• welcome TO .NET WORLD.
• Asp.Net IS Microsoft Own Product.
• File handling is done by Streamreader & streamwriter
• Simple program about File.
• OutPut:
• Writesample.txt Contain
• welcome TO .NET WORLD.Asp.Net IS Microsoft
Own Product.File handling is done by Streamreader
& streamwriter .Simple program about File.
Tasks(to be done in the class session):
• 1)Print first 5 characters from a file in a single line.
• 2)Print number of each line.
• 3)Create two files where 1st
file will contain 1st
&3rd
lines and the other file will contain 2nd
&4th
lines.
ASP.NET Session 8

More Related Content

What's hot

2013 CrossRef Workshops System Update: Guarding Your Data, Andrew Gilmartin
2013 CrossRef Workshops System Update: Guarding Your Data, Andrew Gilmartin2013 CrossRef Workshops System Update: Guarding Your Data, Andrew Gilmartin
2013 CrossRef Workshops System Update: Guarding Your Data, Andrew GilmartinCrossref
 
Logstash + Elasticsearch + Kibana Presentation on Startit Tech Meetup
Logstash + Elasticsearch + Kibana Presentation on Startit Tech MeetupLogstash + Elasticsearch + Kibana Presentation on Startit Tech Meetup
Logstash + Elasticsearch + Kibana Presentation on Startit Tech MeetupStartit
 
ENT302 Deploying Microsoft Exchange and SharePoint on AWS - AWS re: Invent 2012
ENT302 Deploying Microsoft Exchange and SharePoint on AWS - AWS re: Invent 2012ENT302 Deploying Microsoft Exchange and SharePoint on AWS - AWS re: Invent 2012
ENT302 Deploying Microsoft Exchange and SharePoint on AWS - AWS re: Invent 2012Amazon Web Services
 
Moving towards unified logging
Moving towards unified loggingMoving towards unified logging
Moving towards unified loggingPhil Cryer
 
Scaling an ELK stack at bol.com
Scaling an ELK stack at bol.comScaling an ELK stack at bol.com
Scaling an ELK stack at bol.comRenzo Tomà
 
Logging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqLogging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqDoruk Uluçay
 
Customer Intelligence: Using the ELK Stack to Analyze ForgeRock OpenAM Audit ...
Customer Intelligence: Using the ELK Stack to Analyze ForgeRock OpenAM Audit ...Customer Intelligence: Using the ELK Stack to Analyze ForgeRock OpenAM Audit ...
Customer Intelligence: Using the ELK Stack to Analyze ForgeRock OpenAM Audit ...ForgeRock
 
Cassandra Codebase 2011
Cassandra Codebase 2011Cassandra Codebase 2011
Cassandra Codebase 2011gdusbabek
 
Data Processing with Cascading Java API on Apache Hadoop
Data Processing with Cascading Java API on Apache HadoopData Processing with Cascading Java API on Apache Hadoop
Data Processing with Cascading Java API on Apache HadoopHikmat Dhamee
 
Getting to Know the Cassandra Codebase
Getting to Know the Cassandra CodebaseGetting to Know the Cassandra Codebase
Getting to Know the Cassandra Codebasegdusbabek
 
Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programmingChester Hartin
 

What's hot (20)

2013 CrossRef Workshops System Update: Guarding Your Data, Andrew Gilmartin
2013 CrossRef Workshops System Update: Guarding Your Data, Andrew Gilmartin2013 CrossRef Workshops System Update: Guarding Your Data, Andrew Gilmartin
2013 CrossRef Workshops System Update: Guarding Your Data, Andrew Gilmartin
 
Secure code 3rd_party_libs
Secure code 3rd_party_libsSecure code 3rd_party_libs
Secure code 3rd_party_libs
 
Logstash + Elasticsearch + Kibana Presentation on Startit Tech Meetup
Logstash + Elasticsearch + Kibana Presentation on Startit Tech MeetupLogstash + Elasticsearch + Kibana Presentation on Startit Tech Meetup
Logstash + Elasticsearch + Kibana Presentation on Startit Tech Meetup
 
ENT302 Deploying Microsoft Exchange and SharePoint on AWS - AWS re: Invent 2012
ENT302 Deploying Microsoft Exchange and SharePoint on AWS - AWS re: Invent 2012ENT302 Deploying Microsoft Exchange and SharePoint on AWS - AWS re: Invent 2012
ENT302 Deploying Microsoft Exchange and SharePoint on AWS - AWS re: Invent 2012
 
Moving towards unified logging
Moving towards unified loggingMoving towards unified logging
Moving towards unified logging
 
2310 b 12
2310 b 122310 b 12
2310 b 12
 
Compilation
CompilationCompilation
Compilation
 
Scaling an ELK stack at bol.com
Scaling an ELK stack at bol.comScaling an ELK stack at bol.com
Scaling an ELK stack at bol.com
 
C# p4
C# p4C# p4
C# p4
 
Logging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, SeqLogging, Serilog, Structured Logging, Seq
Logging, Serilog, Structured Logging, Seq
 
Customer Intelligence: Using the ELK Stack to Analyze ForgeRock OpenAM Audit ...
Customer Intelligence: Using the ELK Stack to Analyze ForgeRock OpenAM Audit ...Customer Intelligence: Using the ELK Stack to Analyze ForgeRock OpenAM Audit ...
Customer Intelligence: Using the ELK Stack to Analyze ForgeRock OpenAM Audit ...
 
Heap
HeapHeap
Heap
 
Iron python
Iron pythonIron python
Iron python
 
ELK Stack
ELK StackELK Stack
ELK Stack
 
Code
CodeCode
Code
 
Cassandra Codebase 2011
Cassandra Codebase 2011Cassandra Codebase 2011
Cassandra Codebase 2011
 
Data Processing with Cascading Java API on Apache Hadoop
Data Processing with Cascading Java API on Apache HadoopData Processing with Cascading Java API on Apache Hadoop
Data Processing with Cascading Java API on Apache Hadoop
 
Getting to Know the Cassandra Codebase
Getting to Know the Cassandra CodebaseGetting to Know the Cassandra Codebase
Getting to Know the Cassandra Codebase
 
Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programming
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive Extensions
 

Viewers also liked

ASP.NET Session 10
ASP.NET Session 10ASP.NET Session 10
ASP.NET Session 10Sisir Ghosh
 
ASP.NET Session 4
ASP.NET Session 4ASP.NET Session 4
ASP.NET Session 4Sisir Ghosh
 
ASP.NET Session 2
ASP.NET Session 2ASP.NET Session 2
ASP.NET Session 2Sisir Ghosh
 
ASP.NET Session 9
ASP.NET Session 9ASP.NET Session 9
ASP.NET Session 9Sisir Ghosh
 
ASP.NET Session 5
ASP.NET Session 5ASP.NET Session 5
ASP.NET Session 5Sisir Ghosh
 
ASP.NET Session 7
ASP.NET Session 7ASP.NET Session 7
ASP.NET Session 7Sisir Ghosh
 
ASP.NET Session 6
ASP.NET Session 6ASP.NET Session 6
ASP.NET Session 6Sisir Ghosh
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3Sisir Ghosh
 

Viewers also liked (8)

ASP.NET Session 10
ASP.NET Session 10ASP.NET Session 10
ASP.NET Session 10
 
ASP.NET Session 4
ASP.NET Session 4ASP.NET Session 4
ASP.NET Session 4
 
ASP.NET Session 2
ASP.NET Session 2ASP.NET Session 2
ASP.NET Session 2
 
ASP.NET Session 9
ASP.NET Session 9ASP.NET Session 9
ASP.NET Session 9
 
ASP.NET Session 5
ASP.NET Session 5ASP.NET Session 5
ASP.NET Session 5
 
ASP.NET Session 7
ASP.NET Session 7ASP.NET Session 7
ASP.NET Session 7
 
ASP.NET Session 6
ASP.NET Session 6ASP.NET Session 6
ASP.NET Session 6
 
ASP.NET Session 3
ASP.NET Session 3ASP.NET Session 3
ASP.NET Session 3
 

Similar to ASP.NET Session 8

Similar to ASP.NET Session 8 (20)

15. text files
15. text files15. text files
15. text files
 
Files and streams
Files and streamsFiles and streams
Files and streams
 
working with files
working with filesworking with files
working with files
 
15 Text files
15 Text files15 Text files
15 Text files
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
Files in c++
Files in c++Files in c++
Files in c++
 
Get docs from sp doc library
Get docs from sp doc libraryGet docs from sp doc library
Get docs from sp doc library
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Java file
Java fileJava file
Java file
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Files
 
Data file handling
Data file handlingData file handling
Data file handling
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Python - Lecture 9
Python - Lecture 9Python - Lecture 9
Python - Lecture 9
 
Data file handling
Data file handlingData file handling
Data file handling
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
 
CSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdfCSE3146-ADV JAVA M2.pdf
CSE3146-ADV JAVA M2.pdf
 
Input File dalam C++
Input File dalam C++Input File dalam C++
Input File dalam C++
 

More from Sisir Ghosh

ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12Sisir Ghosh
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14Sisir Ghosh
 
ASP.NET Session 16
ASP.NET Session 16ASP.NET Session 16
ASP.NET Session 16Sisir Ghosh
 
ASP.NET System design 2
ASP.NET System design 2ASP.NET System design 2
ASP.NET System design 2Sisir Ghosh
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1Sisir Ghosh
 
Network security
Network securityNetwork security
Network securitySisir Ghosh
 
Module ii physical layer
Module ii physical layerModule ii physical layer
Module ii physical layerSisir Ghosh
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correctionSisir Ghosh
 
Overview of data communication and networking
Overview of data communication and networkingOverview of data communication and networking
Overview of data communication and networkingSisir Ghosh
 
Application layer
Application layerApplication layer
Application layerSisir Ghosh
 

More from Sisir Ghosh (12)

ASP.NET Session 11 12
ASP.NET Session 11 12ASP.NET Session 11 12
ASP.NET Session 11 12
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
 
ASP.NET Session 16
ASP.NET Session 16ASP.NET Session 16
ASP.NET Session 16
 
ASP.NET System design 2
ASP.NET System design 2ASP.NET System design 2
ASP.NET System design 2
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1
 
Transport layer
Transport layerTransport layer
Transport layer
 
Routing
RoutingRouting
Routing
 
Network security
Network securityNetwork security
Network security
 
Module ii physical layer
Module ii physical layerModule ii physical layer
Module ii physical layer
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correction
 
Overview of data communication and networking
Overview of data communication and networkingOverview of data communication and networking
Overview of data communication and networking
 
Application layer
Application layerApplication layer
Application layer
 

Recently uploaded

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

ASP.NET Session 8

  • 1. Application on File Program Session 8
  • 2. Objectives  Typically example of file read & write  Simple File Handling Program  Several Home work
  • 3. Typical example of file read & write try { FileStream aFile = new FileStream("Log.txt", FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(aFile); bool truth = true // Write data to file. sw.WriteLine("Hello to you."); sw.WriteLine("It is now {0} and things are looking good.“,DateTime.Now.ToLongDateString());
  • 4. sw.Write("More than that,"); sw.Write(" it’s {0} that C# is fun.", truth); sw.Close(); } catch (IOException ee) { Console.WriteLine("An IO exception has been thrown!"); Console.WriteLine(ee.ToString()); Console.ReadLine(); return; }
  • 5. • Go to the application directory and find the Log.txt file. It is located in the binDebug folder because you used a relative path. • The WriteLine() method writes the string passed to it, followed immediately by a newline character. • You can see in the example that this causes the next write operation to begin on a new line. • The Write() method simply writes the string passed to it to the file, without a newline character appended. • Two sentence is in one line.
  • 6. The StreamReader Object • try • { • FileStream aFile = new FileStream("Log.txt", FileMode.Open); • StreamReader sr = new StreamReader(aFile); • line = sr.ReadLine(); • // Read data in line by line. • while(line != null) • { • Console.WriteLine(line); • line = sr.ReadLine(); • } • sr.Close(); • }
  • 7. • catch(IOException e) • { • Console.WriteLine("An IO exception has been thrown!"); • Console.WriteLine(e.ToString()); • return; • } • Console.ReadKey();  ReadLine() method to read text from the file.  This method reads text until a new line is found,and returns the resulting text as a string.  The method returns a null when the end of the file has been reached, which you use to test for the end of the file.
  • 8.  Note that you use a while loop, which ensures that the line read isn’t null before any code in the body of the loop is executed. Simple File Handling Program String line,k=""; StreamReader sr = new StreamReader("E:trainingreadsample.txt"); StreamWriter sw = new StreamWriter("E:trainingWritesample.txt"); line = sr.ReadLine();
  • 9. while (line != null) { k += line; line = sr.ReadLine(); } sw.WriteLine(k); sw.Close(); sr.Dispose(); Direct using streamReader & streamWriter
  • 10. Input : readsample.txt Contain • welcome TO .NET WORLD. • Asp.Net IS Microsoft Own Product. • File handling is done by Streamreader & streamwriter • Simple program about File. • OutPut: • Writesample.txt Contain • welcome TO .NET WORLD.Asp.Net IS Microsoft Own Product.File handling is done by Streamreader & streamwriter .Simple program about File.
  • 11. Tasks(to be done in the class session): • 1)Print first 5 characters from a file in a single line. • 2)Print number of each line. • 3)Create two files where 1st file will contain 1st &3rd lines and the other file will contain 2nd &4th lines.