Console.ReadLine(); }//Main

Similar documents
IST311 Chapter13.NET Files (Part2)

Files and Streams. Today you will learn. Files and Web Applications File System Information Reading and Writing with Streams Allowing File Uploads

Files. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

C# Data Manipulation

C# Data Manipulation

RegEx - Numbers matching. Below is a sample code to find the existence of integers within a string.

Cleveland State University. Lecture Notes Feb Iteration Arrays ArrayLists. V. Matos

EEE-448 COMPUTER NETWORKS (Programming) Week -6 C# & IP Programming. The StringBuilder Class. StringBuilder Classes. StringBuilder with Append

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

RegEx-validate IP address. Defined below is the pattern for checking an IP address with value: String Pattern Explanation

Chapter 14: Files and Streams

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

File Handling Programming 1 C# Programming. Rob Miles

Windows File I/O. Files. Collections of related data stored on external storage media and assigned names so that they can be accessed later

Networking Haim Michael. All Rights Reserved.

class Class1 { /// <summary> /// The main entry point for the application. /// </summary>

A Summoner's Tale MonoGame Tutorial Series. Chapter 15. Saving Game State

Hands-On Lab. Introduction to the Windows Azure AppFabric Service Bus Futures. Lab version: Last updated: 11/16/2010. Page 1

LIPNET OUTBOUND API FORMS DOCUMENTATION

Advanced Programming Methods. Lecture 9 - Generics, Collections and IO operations in C#

Introduction. Lecture 5 Files and Streams FILE * FILE *

F# - BASIC I/O. Core.Printf Module. Format Specifications. Basic Input Output includes

Lecture 5 Files and Streams

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Problem Statement. B1: average speed

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science And Engineering

Advanced Programming C# Lecture 2. dr inż. Małgorzata Janik

API Guide MSS-8 and MVS-16

Problem Statement. A1: being lapped on the track

Chapter 8 Files. File Streams

INFORMATICS LABORATORY WORK #2

Threads & Networking

Basic File Handling and I/O

About 1. Chapter 1: Getting started with openxml 2. Remarks 2. Examples 2. Installation of OpenXML SDK and productivity tool on your computer 2

From what you have learned about C# programming so far, you should

Engr 123 Spring 2018 Notes on Visual Studio

Main Game Code. //ok honestly im not sure, if i guess its a class ment for this page called methodtimer that //either uses the timer or set to timer..

Learn C# Errata. 3-9 The Nullable Types The Assignment Operators

UNIVERSITY OF THE FREE STATE MAIN & QWA-QWA CAMPUS RIS 124 DEPARTMENT: COMPUTER SCIENCE AND INFORMATICS CONTACT NUMBER:

TECHNOLOGIES. Kick Starting OOPS &.Net Encapsulation Ø Class Ø Struct Ø Interface, Ø Enum Ø Abstraction Ø Access modifiers in.net

CSIS 1624 CLASS TEST 6

Apex TG India Pvt. Ltd.

1 C# 6.0: Practical Guide 6.0. Practical Guide. By: Mukesh Kumar.

How to read/write text file

A Summoner's Tale MonoGame Tutorial Series. Chapter 10. Creating Avatars

Tutorial on text transformation with pure::variants

Industrial Programming

9 Hashtables and Dictionaries

This tutorial has been prepared for the beginners to help them understand basics of c# Programming.

OVERVIEW ENVIRONMENT PROGRAM STRUCTURE BASIC SYNTAX DATA TYPES TYPE CONVERSION

Lecture 8 Building an MDI Application

emkt Browserless Coding For C#.Net and Excel

Chapter 11. Data Files The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

For this example, we will set up a small program to display a picture menu for a fast food take-away shop.

The contents of this document are directly taken from the EPiServer SDK. Please see the SDK for further technical information about EPiServer.

// Precondition: None // Postcondition: The address' name has been set to the // specified value set;

PULSE - API. The purpose of this document is to provide example requests and responses for all relevant Pulse services requests

SharePoint File System Replication Tool. Formation Technology, 2006

You can call the project anything you like I will be calling this one project slide show.

Simple FTP demo application using C#.Net 2.0

Occupied versus Unoccupied

IST311 Chapter 8: C# Collections - Index-Sequential Search List & Dictionary PROGRAM

Configuration Web Services for.net Framework

Brian Kiser November Vigilant C# 2.5. Commonwealth of Kentucky Frankfort, Kentucky

CS 200 File Input and Output Jim Williams, PhD

05/31/2009. Data Files

6: Arrays and Collections

RIS214. Class Test 3

Introduction to C# Applications

CSC 355 PROJECT 4 NETWORKED TIC TAC TOE WITH WPF INTERFACE

C# - Reflection. It allows examining various types in an assembly and instantiate these types.

Set Up a Two Factor Authentication with SMS.

Create a cool image gallery using CSS visibility and positioning property

Justin Jones 21 st February 2013 Version 1.1 Setting up an MVC4 Multi-Tenant Site

Project #1 Computer Science 2334 Fall 2008

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

An implementation of the relational k-means algorithm

Broker/Universal Messaging

6: Arrays and Collections

Lesson07-Arrays-Part4. Program class. namespace Lesson07ArraysPart4Prep { class Program { static double METER_TO_INCHES = 100 / 2.

COSC 6397 Big Data Analytics. Distributed File Systems (II) Edgar Gabriel Fall HDFS Basics

File Practice Problems

Case study: ext2 FS 1

I/O STREAM (REQUIRED IN THE FINAL)

Lab - 1. Solution : 1. // Building a Simple Console Application. class HelloCsharp. static void Main() System.Console.WriteLine ("Hello from C#.

String sequence of characters string Unicode Characters immutable they cannot be changed after they have been created.

Your Company Name. Tel: Fax: Microsoft Visual Studio C# Project Source Code Output

UNIVERSITY OF THE FREE STATE DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS CSIS 2614 MODULE TEST 2

DAD Lab. 1 Introduc7on to C#

A1 Problem Statement Willie s Push-ups

COSC 6397 Big Data Analytics. Distributed File Systems (II) Edgar Gabriel Spring HDFS Basics

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

mode uid gid atime ctime mtime size block count reference count direct blocks (12) single indirect double indirect triple indirect mode uid gid atime

Case study: ext2 FS 1

Implementing a chat button on TECHNICAL PAPER

OpenScape Voice V8 Application Developers Manual. Programming Guide A31003-H8080-R

API Guide MSS-8 and MVS-16

CALCULATOR APPLICATION

Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection)

You briefly saw in Chapter 1 how to declare a new class called

Transcription:

IST 311 Lecture Notes Chapter 13 IO System using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; namespace Chapter13FileSystem class Program static void Main(string[] args) Experiment00(); // using System.IO Experiment01(); // write a data set Experiment02(); // read a disk data set List<Person> ladies = Experiment03(); //split line to get fragments(first, last, phone) Experiment04(ladies); // echo collection of Person objects Experiment05(); // using BinaryReader & BinaryWriter Experiment06(); // random file Experiment07(); // WebClient for Internet exchange Console.ReadLine(); //Main ---------------------------------------------------------------------------- private static void Experiment07() Console.WriteLine("\nExperiment07 >>>\n"); // create a new instance of WebClient to get NPR RSS Headlines page WebClient client = new WebClient(); string urlheadlinesnpr = "http://stage1-s.npr.org/rss/rss.php?id=1001"; // in this example the response is an HTML page string response = client.downloadstring(urlheadlinesnpr); Console.WriteLine("Response:\n0", response); Console.WriteLine(e.Message); private static void Experiment05() Console.WriteLine("\nExperiment05 >>>\n"); //using BinaryReader & BinaryWriter FileStream filstream = new FileStream(@"c:\temp\test.bin", FileMode.Create); BinaryWriter binwriter = new BinaryWriter(filStream); double avalue = 3.14; binwriter.write("hello world"); for (int i = 0; i < 11; i++) binwriter.write(i);

binwriter.write(avalue); binwriter.close(); filstream.close(); string strvalue; int intvalue; double douvalue; //using BinaryReader (continuation) FileStream filstreamin = new FileStream(@"c:\temp\test.bin", FileMode.Open); BinaryReader binreader = new BinaryReader(filStreamIn); //filstreamin.seek(0, SeekOrigin.Begin); strvalue = binreader.readstring(); Console.WriteLine("STRING >> 0", strvalue); for (int i = 0; i < 11; i++) intvalue = binreader.readint32(); Console.WriteLine("INT >> 0", intvalue); douvalue = binreader.readdouble(); Console.WriteLine("DOUBLE >> 0", douvalue); Console.WriteLine("\nDone...\n"); private static void Experiment06() Console.WriteLine("\nExperiment06 >>>\n"); //read & write fixed-length records to a random file String rec1 = "111 FirstName1 LastName1 Phone1"; String rec2 = "222 FirstName2 LastName2 Phone2"; String rec3 = "333 FirstName3 LastName3 Phone3"; int reclen = rec1.length; byte[] buffer = new byte[reclen]; //buffer = Encoding.ASCII.GetBytes(rec1); //Console.WriteLine("buffer " + buffer); //rec1 = Encoding.ASCII.GetString(buffer); //Console.WriteLine("string " + rec1); //create original version of the file using (FileStream fs = new FileStream(@"c:\temp\people.dat", FileMode.Create)) using (BinaryWriter bw = new BinaryWriter(fs)) buffer = Encoding.ASCII.GetBytes(rec1); bw.write(buffer); buffer = Encoding.ASCII.GetBytes(rec2); bw.write(buffer); buffer = Encoding.ASCII.GetBytes(rec3); bw.write(buffer); //read from random file (traversing in reverse order) using (FileStream fs = new FileStream(@"c:\temp\people.dat", FileMode.Open)) using (BinaryReader br = new BinaryReader(fs)) for (int position = 2; position >= 0; position--)

int offset = position * reclen; fs.seek(offset, SeekOrigin.Begin); br.read(buffer, 0, reclen); Console.WriteLine("Position 0 Record: 1", position, Encoding.ASCII.GetString(buffer)); // ------------------------------------------------------------------------- // misc. operators, learning how to use the System.IO namespace utilities private static void Experiment00() Console.WriteLine("\nExperiment00 >>>\n"); File.Delete(@"c:/temp/dummyTextFile1.txt"); File.Delete(@"c:/temp/dummyTextFile2.txt"); File.AppendAllLines(@"c:/temp/dummyTextFile1.txt", new string[] " Line1\n Line2\n Line3\n" ); File.AppendAllText(@"c:/temp/dummyTextFile1.txt", " Line4\n Line5\n Line6"); File.Copy(@"c:/temp/dummyTextFile1.txt", @"c:/temp/dummytextfile2.txt"); Console.WriteLine(File.Exists(@"c:/temp/dummyTextFile1.txt")); Console.WriteLine(File.GetAccessControl(@"c:/temp/dummyTextFile1.txt")); Console.WriteLine(File.GetAttributes(@"c:/temp/dummyTextFile1.txt")); String filename = @"c:/temp/dummytextfile1.txt"; Console.WriteLine("FileName: 0", filename); Console.WriteLine("Attributes: 0", File.GetAttributes(fileName)); Console.WriteLine("Created: 0", File.GetCreationTime(fileName)); Console.WriteLine("Last Accessed: 0", File.GetLastAccessTime(fileName)); FileInfo fileinfo = new FileInfo(@"c:/temp/dummyTextFile1.txt"); Console.WriteLine("FileInfo.Length 0", fileinfo.length); Console.WriteLine("FileInfo.FullName 0", fileinfo.fullname); Console.WriteLine("FileInfo.DirectoryName 0", fileinfo.directoryname); DirectoryInfo directoryinfo = new DirectoryInfo(@"c:\temp"); Console.WriteLine("directoryInfo.FullName 0", directoryinfo.fullname); Console.WriteLine(); DirectoryInfo dir = new DirectoryInfo(@"c:/temp"); Console.WriteLine("Current Directory: \n0\n", Directory.GetCurrentDirectory()); foreach (FileInfo file in dir.getfiles("*.zip")) Console.WriteLine(file.FullName.PadRight(35, ' ') + " " + file.lastwritetime.tostring().padright(25, ' ') + file.length.tostring().padright(10, ' ')); Console.WriteLine(e.Message); Console.WriteLine("\nDone Experiment01B\n");

private static void Experiment04(List<Person> ladies) Console.WriteLine("\nExperiment04 >>>\n"); //Print a list of Person objects (firstname, last, phone) Console.WriteLine("\nExperiment04"); foreach (Person p in ladies) Console.WriteLine(p); // ---------------------------------------------------------------------- private static List<Person> Experiment03() Console.WriteLine("\nExperiment03 >>>\n"); //read a file holding ladies firstname, LastName, phoneno //use the acquired data to create a List<Person> collection List<Person> people = new List<Person>(); //StreamReader infile = new StreamReader(@"c:/temp/mycsdemofile1.txt"); StreamReader infile = new StreamReader(@"c:/temp/westerosladies.txt"); String line; while ((line = infile.readline())!= null) Console.WriteLine("\nECHO>>> " + line); string[] tokens = line.split(); Console.WriteLine(tokens[0]); Console.WriteLine(tokens[1]); Console.WriteLine(tokens[2]); Person p = new Person(tokens[0], tokens[1], tokens[2]); Console.WriteLine(p); people.add(p); infile.close(); Console.WriteLine("PROBLEM: " + e.message); return people; // ---------------------------------------------------------------------------- // read and display on console data from a text file on disk private static void Experiment02() Console.WriteLine("\nExperiment02 >>>\n"); if (!File.Exists(@"c:/temp/westerosladies.txt")) return; StreamReader infile = new StreamReader(@"c:/temp/westerosladies.txt"); String line; while ((line = infile.readline())!= null) Console.WriteLine("ECHO>>> " + line); infile.close(); Console.WriteLine("PROBLEM: " + e.message);

// ------------------------------------------------------------------------------- // write ten lines to a disk file, each holding dummy firstname, last, phone private static void Experiment01() Console.WriteLine("\nExperiment01 >>>\n"); StreamWriter outputfile = new StreamWriter(@"c:/temp/westerosladies.txt"); for (int i = 0; i < 10; i++) outputfile.writeline("ladyfirstname0 ladylastname0 ladyphone0", i); outputfile.close(); Console.WriteLine("Done Phase1"); Console.WriteLine("PROBLEM: " + e.message); Experiment00 >>> True System.Security.AccessControl.FileSecurity Archive FileName: c:/temp/dummytextfile1.txt Attributes: Archive Created: 4/12/2016 12:05:57 PM Last Accessed: 4/13/2016 1:41:26 PM FileInfo.Length 43 FileInfo.FullName c:\temp\dummytextfile1.txt FileInfo.DirectoryName c:\temp directoryinfo.fullname c:\temp Current Directory: C:\temp\Chapter13FileSystem\Chapter13FileSystem\bin\Debug c:\temp\99-camera02.zip 12/19/2014 4:41:14 PM 1935945 c:\temp\lesson3.zip 4/12/2016 7:22:56 PM 5309010 c:\temp\westerosladies.zip 4/12/2016 7:22:17 PM 240 Done Experiment01B Experiment01 >>> Done Phase1 Experiment02 >>> ECHO>>> ladyfirstname0 ladylastname0 ladyphone0 ECHO>>> ladyfirstname1 ladylastname1 ladyphone1 ECHO>>> ladyfirstname2 ladylastname2 ladyphone2 ECHO>>> ladyfirstname3 ladylastname3 ladyphone3 ECHO>>> ladyfirstname4 ladylastname4 ladyphone4 ECHO>>> ladyfirstname5 ladylastname5 ladyphone5

ECHO>>> ladyfirstname6 ladylastname6 ladyphone6 ECHO>>> ladyfirstname7 ladylastname7 ladyphone7 ECHO>>> ladyfirstname8 ladylastname8 ladyphone8 ECHO>>> ladyfirstname9 ladylastname9 ladyphone9 Experiment03 >>> ECHO>>> ladyfirstname0 ladylastname0 ladyphone0 ladyfirstname0 ladylastname0 ladyphone0 Person[First=ladyFirstName0,Last=ladyLastName0, Phone=ladyPhone0] ECHO>>> ladyfirstname1 ladylastname1 ladyphone1 ladyfirstname1 ladylastname1 ladyphone1 Person[First=ladyFirstName1,Last=ladyLastName1, Phone=ladyPhone1] ECHO>>> ladyfirstname2 ladylastname2 ladyphone2 ladyfirstname2 ladylastname2 ladyphone2 Person[First=ladyFirstName2,Last=ladyLastName2, Phone=ladyPhone2] ECHO>>> ladyfirstname3 ladylastname3 ladyphone3 ladyfirstname3 ladylastname3 ladyphone3 Person[First=ladyFirstName3,Last=ladyLastName3, Phone=ladyPhone3] ECHO>>> ladyfirstname4 ladylastname4 ladyphone4 ladyfirstname4 ladylastname4 ladyphone4 Person[First=ladyFirstName4,Last=ladyLastName4, Phone=ladyPhone4] ECHO>>> ladyfirstname5 ladylastname5 ladyphone5 ladyfirstname5 ladylastname5 ladyphone5 Person[First=ladyFirstName5,Last=ladyLastName5, Phone=ladyPhone5] ECHO>>> ladyfirstname6 ladylastname6 ladyphone6 ladyfirstname6 ladylastname6 ladyphone6 Person[First=ladyFirstName6,Last=ladyLastName6, Phone=ladyPhone6] ECHO>>> ladyfirstname7 ladylastname7 ladyphone7 ladyfirstname7 ladylastname7 ladyphone7 Person[First=ladyFirstName7,Last=ladyLastName7, Phone=ladyPhone7] ECHO>>> ladyfirstname8 ladylastname8 ladyphone8 ladyfirstname8 ladylastname8 ladyphone8 Person[First=ladyFirstName8,Last=ladyLastName8, Phone=ladyPhone8] ECHO>>> ladyfirstname9 ladylastname9 ladyphone9 ladyfirstname9 ladylastname9 ladyphone9 Person[First=ladyFirstName9,Last=ladyLastName9, Phone=ladyPhone9]

Experiment04 >>> Experiment04 Person[First=ladyFirstName0,Last=ladyLastName0, Phone=ladyPhone0] Person[First=ladyFirstName1,Last=ladyLastName1, Phone=ladyPhone1] Person[First=ladyFirstName2,Last=ladyLastName2, Phone=ladyPhone2] Person[First=ladyFirstName3,Last=ladyLastName3, Phone=ladyPhone3] Person[First=ladyFirstName4,Last=ladyLastName4, Phone=ladyPhone4] Person[First=ladyFirstName5,Last=ladyLastName5, Phone=ladyPhone5] Person[First=ladyFirstName6,Last=ladyLastName6, Phone=ladyPhone6] Person[First=ladyFirstName7,Last=ladyLastName7, Phone=ladyPhone7] Person[First=ladyFirstName8,Last=ladyLastName8, Phone=ladyPhone8] Person[First=ladyFirstName9,Last=ladyLastName9, Phone=ladyPhone9] Experiment05 >>> STRING >> Hello world INT >> 0 INT >> 1 INT >> 2 INT >> 3 INT >> 4 INT >> 5 INT >> 6 INT >> 7 INT >> 8 INT >> 9 INT >> 10 DOUBLE >> 3.14 Done... Experiment06 >>> Position 2 Record: 333 FirstName3 LastName3 Phone3 Position 1 Record: 222 FirstName2 LastName2 Phone2 Position 0 Record: 111 FirstName1 LastName1 Phone1 Experiment07 >>> Response: <!DOCTYPE html> <html> <head> <title>npr: Page Not Found</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="content-language" content="en-us" />... </head> <body class="missing-404"> <!--#include virtual="/include/navigation/news/header.html"--> <div id="wrapper">... <p class="bottom-missing">it's a shame that your page is lost, but stick around to browse through NPR stories about lost people, places, and things that still haven' <div class="missing-story"> <a href="/templates/story/story.php?storyid=1032135"><img /404/404-1.jpg" alt="amilia Earhart" /></a> <h2><a href="/templates/story/story.php?storyid=1032135">a... </body> </html>