Openen en Opslaan class Tekst : Form { } TextBox invoer; void lees (string naam) { } void schrijf (string naam) { } StreamReadersr = new StreamReader (naam);

Slides:



Advertisements
Similar presentations
A Guide to Advanced Java Faculty:Nguyen Ngoc Tu. 2 Operating System Application #1 Application #2 Java Virtual Machine #1 Local Memory Shared Memory Threads.
Advertisements

1 Streams and Input/Output Files Part 2. 2 Files and Exceptions When creating files and performing I/O operations on them, the systems generates errors.
Console applicatie static void Main ( ) class Hallo { } { } Console. WriteLine("Hallo " + naam + "!" ); statische methodestatische methoden Console. WriteLine("Wat.
Reading and Writing Text Files Svetlin Nakov Telerik Corporation
Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag functie definitions;.h files;
Data Structures and Collections
Onderwerpen voor vandaag
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
C# - Files and Streams Outline Files and Streams Classes File and Directory Creating a Sequential-Access File Reading Data from a Sequential-Access.
Files & Streams. Files Introduction Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.
Hoofdstuk 13 Object-georiënteerd ontwerp. Methode-aanroep: Type van parameters void paint(Graphics g) { g.drawRect( ); class Graphics { void drawRect(int.
Toepassing: schets-editor Canvas om op te tekenen Tools Controls Menu.
Toepassing: schets-editor
Array nDeclaratie nCreatie nOpvragen nWijzigen nLengte String [ ] a; a = new String[10]; ……a[5]…… a[5] = ……; …a.length… …is eigenlijk overbodig! ArrayList.
Wordpress Hoe doe je dat bij DSE Bloggen met. Log in op de homepage, klik in mijn account op Wordpress installeren.
C# Programming: From Problem Analysis to Program Design1 Working with Files C# Programming: From Problem Analysis to Program Design 3 rd Edition 13.
Understanding Input/Output (I/O) Classes Lesson 5.
Collection types Collection types.
Lecture Set 12 Sequential Files and Structures Part B – Reading and Writing Sequential Files.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
Two Ways to Store Data in a File Text format Binary format.
Chapter 12 Working with Files CIS 3260 Introduction to Programming using C# Hiro Takeda.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Lector: Aliyev H.U. Lecture №5 Telecommunication network software design with.NET. Using streams for network programming TASHKENT UNIVERSITY OF INFORMATION.
1 14/10/58Dr.Mud-Armeen Munlin 1 Files and Streams ผศ. ดร. หมัดอามีน หมันหลิน Faculty of IST, MUT
Streams & File Input/Output Basics C#.Net Development Version 1.1.
Files and Streams File Types, Using Streams, Manipulating Files SoftUni Team Technical Trainers Software University
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
CS360 Windows Programming
BIM313 – Advanced Programming File Operations 1. Contents Structure of a File Reading/Writing Texts from/to Files File and Directory Operations 2.
Oct 2007 SDP-MSc Slide 1 Section 9 Graphic Programming.
Chapter 8 Files 1/4/20161Copyright © 2012 Thomas P. Skinner.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Input and Output 23: Input and Output
CSC 298 Streams and files.
Data Structures and Collections Principles.NET: –Two libraries: System.Collections System.Collections.Generics FEN 2014UCN Teknologi/act2learn1 Deprecated.
(2.2) Hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en methode using Android.OS; using Android.App; using Android.Widget;
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Ajay Tripathi Input Output. Ajay Tripathi Input/output (IO) refers to the operations for reading and writing data to streams and files. In the.NET Framework,
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
Module 13: Properties and Indexers. Overview Using Properties Using Indexers.
Files and Streams. What is a file? Up until now, any stored data within a program is lost when the program closes. A file is a permanent way to store.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
1 Statements © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
Files and Streams Lec Introduction  Files are used for long-term retention of large amounts of data, even after the program that created the.
Module 5: Programming with C#. Overview Using Arrays Using Collections Using Interfaces Using Exception Handling Using Delegates and Events.
File Output Writing data out to a file 1. Output to files  StreamWriter : An object in the System.IO namespace that lets you print output to a destination.
Chapter 6: Creating Windows–based Applications 1 Microsoft® Visual C# 2008.
Lecture 18 File I/O Richard Gesick. File Input / Output Consider that a program may want to make its data persistent (or not rely upon the user for input)
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 2 nd Lecture Pavel Ježek
INF230 Basics in C# Programming
Gameprogrammeren: Klassen en objecten in Painter
Input and Output 23: Input and Output
string versus array Klasse Type met speciale syntax Indexer -notatie
C# Programming: From Problem Analysis to Program Design
Voorbeeld-programma's
(H9.1) CirkelKlikker ARRAY int x, y; [ ] int n=0;
2e Deeltentamen Nagekeken werk ligt voor in de zaal (alfabetisch op achternaam) Neem het even mee, opg.13 wordt in het college besproken Discussies over.
Defiana Arnaldy, M.Si File and Stream I/O Defiana Arnaldy, M.Si
File Types, Using Streams, Manipulating Files
Lectures 12 Files & Streams Dr. Eng. Ibrahim El-Nahry.
Chapter 3 The .NET Framework Class Library (FCL)
Files & Streams.
Lecture 16 File I/O Richard Gesick.
鄭士康 國立台灣大學 電機工程學系/電信工程研究所/ 資訊網路與多媒體研究所
.Net Framework: A Survey of Important Libraries
Chengyu Sun California State University, Los Angeles
Jim Fawcett CSE775 – Distributed Objects Spring 2012
Presentation transcript:

Openen en Opslaan class Tekst : Form { } TextBox invoer; void lees (string naam) { } void schrijf (string naam) { } StreamReadersr = new StreamReader (naam); sr. ReadToEnd ( )this.invoer.Text =; sr. Close ( ) ; StreamWritersw = new StreamWriter (naam); sw. Write () ;this.invoer.Text sw. Close ( ) ; this.Text = naam;

Klassen om files te lezen en te schrijven Stream FileStream MemoryStream NetworkStream BufferedStream GZipStream CryptoStream TextWriter StreamWriter StringWriter BinaryWriter XmlWriter TextReader StreamReader StringReader BinaryReader XmlReader Object store decorator

Klassen om files te lezen en te schrijven Stream FileStream MemoryStream NetworkStream StreamWriterStreamReader leest en schrijft bytes leest string en char schrijft string en char leest/schrijft een file leest/schrijft het geheugen leest/schrijft het netwerk

Methoden van Stream Stream FileStream MemoryStream NetworkStream class FileStream { } int Read (byte[] doel, int max) { } for (int t=0; t<max; t++) { } int b = this.ReadByte(); if (b==–1) return t; doel[t] =b ; (byte) return max; Stream int ReadByte ( ) virtual { /* leeg */ } class FileStream : Stream { } override int ReadByte ( ) { return } abstract ;

Abstracte methode/klasse Stream FileStream MemoryStream NetworkStream nAbstracte methode: methode zonder body nAbstracte klasse: bevat abstracte methode ●kun je geen new object van maken ●alleen bedoeld als superklasse Brush SolidBrush HatchBrush

Decorator Streams Stream FileStream MemoryStream NetworkStream Stream str; BufferedStream GZipStream CryptoStream store decorator str = new FileStream ( "test", FileMode.Create ); GZipStream klein; klein = new GZipStream ( str ) ; klein.Write( mijnByteArray ); geef het onderliggende store-medium "in beheer" CryptoStream geheim; geheim = new CryptoStream ( klein ) ; je kunt decorators combineren

Reader en Writer Stream FileStream MemoryStream NetworkStream BufferedStream GZipStream CryptoStream TextWriter StreamWriter StringWriter TextReader StreamReader StringReader Object store decorator leest en schrijft bytes leest string en char schrijft string en char vanuit een Stream vanuit een String

Reader en Writer Stream FileStream MemoryStream NetworkStream BufferedStream GZipStream CryptoStream TextWriter StreamWriter StringWriter TextReader StreamReader StringReader Object store decorator leest en schrijft bytes leest string en char schrijft string en char Stream str; str = new FileStream ( "test.txt", FileMode.Open ); TextReader lezer; lezer = new StreamReader ( str ); string s; s = lezer. ReadToEnd ( );

Reader en Writer Stream FileStream MemoryStream NetworkStream BufferedStream GZipStream CryptoStream TextWriter StreamWriter StringWriter TextReader StreamReader StringReader Object store decorator leest en schrijft bytes leest string en char schrijft string en char Stream str; str = new FileStream ( "test.txt", FileMode.Open ); TextReader lezer; lezer = new StreamReader ( str ); string s; s = lezer. ReadToEnd ( ); lezer = new StreamReader ( "test.txt" ); convenience-methode

Reader en Writer Stream FileStream MemoryStream NetworkStream BufferedStream GZipStream CryptoStream TextWriter StreamWriter StringWriter BinaryWriter XmlWriter TextReader StreamReader StringReader BinaryReader XmlReader Object store decorator leest en schrijft bytes leest string en char schrijft string en char leest int en double leest XML-teksten

Figuur 32 Stream FileStream Memory Stream Network Stream Buffered Stream GZip Stream Crypto Stream TextReader StreamReader StringReader BinaryReader XmlReader Object store decorator (Filenaam,FileMode) ( ) (Socket) (Stream, int) (Stream, CompressionMode) (Stream, CryptoStreamMode) (Stream) (Filenaam) (String) (Stream).Create(…) (Stream, Encoding) (wat de constructor nodig heeft) statische methode die het constructie-werk doet

Encoding: char naar byte nASCII ●1 byte per char, <128 nUnicode ●2 bytes per char aäAα F 4161E4B nBigEndianUnicode ●2 bytes, grote eerst 4161E4B nLatin-1 (iso ) ●1 byte per char, < E4 3F nUTF8 ●1/2/3 bytes per char 4161A4B1C3CE header FEFF FE EFBBBF

Encoding

Hoofdstuk 11.1 Algoritmen: Console-applicaties

Console applicatie static void Main ( ) class Hallo { } { } Console. WriteLine("Hallo " + naam + "!" ); statische methodestatische methoden Console. WriteLine("Wat is je naam?"); string naam = Console. ReadLine( );

class Console static void WriteLine( string s ) class Console { } { } Console. Out. WriteLine( s ); static string ReadLine( ) { } return Console. In. ReadLine( ); TextReader In { get; } TextWriter Out { get; }

class TextReader abstract string ReadLine( ) ; class TextReader { } string ReadToEnd( ) { } string resultaat, regel; return resultaat; regel = this.ReadLine( ); while (regel != null) { } resultaat += regel + "\n" ; regel = this.ReadLine( ); TextReader StreamReader StringReader abstract

class TextReader abstract string ReadLine( ) ; class TextReader { } string ReadToEnd( ) { } string resultaat, regel; return resultaat; while (regel != null) { } resultaat += regel + "\n" ; regel = this.ReadLine( ); ( (regel = this.ReadLine()) != null ) en meteen testen regel = this.ReadLine( ); toekennen

Commandline programma $>date Fri Oct 29, 11:30 $> ls aap.txt hallo.doc prog.cs $> grep void prog.cs prog.cs, line 6: void Main() prog.cs, line 10: void teken() $>ls > files.txt $> parameters voor het programma output redirection

Voorbeeld file-processor nlaat alle regels van de files zien waarin het gegeven patroon voorkomt n(met filenaam en regelnummer) grep patroon file1 file2... Unix-commando

Grep: main class Grep if (params.Length==0) Console.WriteLine("Usage: java Grep pat file..."); else static void Main ( for (int t=1; t<params.Length; t++) Grep.bewerk( params[0], params[t] ); { } { )string [ ] params

Grep: bewerk static void bewerk (String pat, String naam) { regel=buffer.ReadLine() Console.WriteLine( naam if ( regel. Contains (pat) ) reader = new StreamReader (naam); TextReader reader; String regel; while ()( ) != null ; n++ for (int n=1; + n+ regel ); if (naam=="") reader = Console.In; else try { } catch (Exception e) { Console.WriteLine(naam + e); }

Array nDeclaratie nCreatie nOpvragen nWijzigen nLengte String [ ] a; a = new String[10]; ……a[5]…… a[5] = ……; …a.Length… …is eigenlijk overbodig! List a; a = new List(); …a.Get(5)… a.Set(5,…); …a.Count… array: oject dat een rij waarden bevat, met speciale notaties List: array “ingepakt” in een klasse, met standaard notaties nInvoegen nAchtervoegen a.Insert(5,…); List a; a = new List (); a.Add(…); uitgebreide ……a[5]…… a[5] = ……;

Voorbeeld: array class Voorbeeld : Form { } Voorbeeld ( ) { } void klik(object o, AE ae) { } TextBox in; Button b; void teken(object o, PEA pea) { } in = new TextBox(); b = new Button(); b.Click += klik; this.Paint += teken; String s = in.Text; alles[n] = s; n++; this.Invalidate(); String [] alles; int n; alles = new String[100]; n = 0; for (int t=0; t<n; t++) { pea.Graphics.DrawString( alles[t],......, y ); y+=20; } int y = 50; if (n<100) { } List List alles; alles = new List ( ); alles.Add(s); alles[t] alles.Count;t++)

Varianten van List ICollectionIList ISet interface ICollection { void Add(Elem x); bool Remove(Elem x); bool Contains(Elem x); int Count { get; }; void Clear(); } interface IList : ICollection { Elem this[int n] { get; set; } ; int IndexOf(Elem x); void Insert(int n, Elem x); void RemoveAt(int n); } genummerd zonder dubbele

Voorbeeld: Collection class Voorbeeld : Form { } Voorbeeld ( ) { } void klik(object o, AE ae) { } TextBox in; Button b; void teken(object o, PEA pea) { } in = new TextBox(); b = new Button(); b.Click += klik; this.Paint += teken; String s = in.Text; alles[n] = s; n++; this.Invalidate(); alles = new String[100]; n = 0; for (int t=0; t<n; t++) { pea.Graphics.DrawString( alles[t],......, y ); y+=20; } int y = 50; List alles; alles = new List ( ); alles.Add(s); alles[t] alles.Count;t++) IList alles; ICollection alles; LinkedList

Hoe doorloop je een Collection? nList nCollection for (int t=0; t<alles.Count; t++) doeIetsMet( alles[t] ); foreach (String s in alles) doeIetsMet( s ); opdracht for)(expropdrachtexpr ;; Speciale syntax voor specifieke situatie met bepaalde klasse typeexprinnaamforeach()opdracht

Implementaties van Collections LinkedList Queue Stack List HashSet SortedSet SortedList Sorted Dictionary IList ISet IDictionary ICollection

Implementaties van Collections IEnumerable IEnumerator IComparator LinkedList Queue Stack List HashSet SortedSet SortedList Sorted Dictionary IList ISet IDictionary ICollection

Toepassing: schets-editor SchetsWin Tools Akties Menu MDI- Container SchetsControl

Schets: Klasse-ontwerp Control Form UserControl Hoofdscherm SchetsWin SchetsControl Schets ImageBitmap Button Base Button RadioButton SchetsEditor System.Windows.Forms System.Drawing Program Container Control ISchetsTool TekstTool LijnTool PenTool GumTool RechthTool VolRechthTool TweepuntTool Startpunt Tool

Member-variabelen class SchetsWinclass SchetsControlclass Schets : Form: UserControl { } { } { } MenuStrip strip; SchetsControl sc; ISchetsTool huidig; Schets schets; Color kleur; Bitmap bm;

Schoonmaakwerk doen class SchetsWinclass SchetsControlclass Schets : Form: UserControl { } { } { } MenuStrip strip; SchetsControl sc; ISchetsTool huidig; Schets schets; Color kleur; Bitmap bm; void teken(...PEA p) { } schets.Teken (p.Graphics); void Teken (Graphics g) { } gr.DrawImage (bm, 0, 0); void Schoon(...AE a) { } schets.Schoon(); void Schoon( ) { } this.Invalidate(); Graphics. FromImage(bm); Graphics g = g.FillRectangle (White,0,0,w,h); SchetsWin() { } sc = new SchetsControl(); this.maakAkties(); void maakAkties() { } Button b b.Text = "Clear"; b.Click += sc.Schoon; = new Button();

Tool kiezen class SchetsWin : Form { } MenuStrip strip; SchetsControl sc; ISchetsTool huidig; void klikTool ( object obj, AE ae ) { } huidig = obj. Tag(Button)() (ISchetsTool) void maakTools( { } ICollection tools) foreach (ISchetsTool tool in tools) { } RadioButton r = new RadioButton(); r.Text = tool.ToString(); r.Click += this.klikTool; r.Tag = tool;

Tool gebruiken class SchetsWin : Form { } MenuStrip strip; SchetsControl sc; ISchetsTool huidig; SchetsWin ( ) { } sc.MousePress += void klikTool ( object obj, AE ae ) { } huidig = obj. Tag(Button)() (ISchetsTool) sc = new SchetsControl ( ); this.muis; void muis ( object o, MEA mea) { } huidig.MuisVast( interface ISchetsTool { } void MuisVast( mea.Location) Point p); sc, SchetsControl s,

Tool gebruiken class SchetsWin : Form { } MenuStrip strip; SchetsControl sc; ISchetsTool huidig; SchetsWin ( ) { sc.MousePress += void klikTool ( object obj, AE ae ) { } huidig = obj. Tag(Button)() (ISchetsTool) sc = new SchetsControl ( ); ( object o, MEA mea) { } huidig.MuisVast( sc, mea.Location); interface ISchetsTool { } void MuisVast( Point p); SchetsControl s, } => anonieme methode

Schets-tools (1) ISchetsTool interface ISchetsTool { } void muisVast ( SchetsControl s, Point p) ; void muisLos ( SchetsControl s, Point p) ; void muisDrag ( Schetscontrol s, Point p ) ; void Letter ( SchetsControl s, char k) ;

Schets-tools (2) ISchetsTool Startpunt Tool abstract class StartpuntTool : ISchetsTool { } virtual void MuisVast ( SchetsControl s, Point p) {startpunt = p; } Point startpunt ; abstract void MuisDrag ( SchetsControl s, Point p) ; abstract void Letter ( SchetsControl s, Point p) ; virtual void MuisLos ( SchetsControl s, Point p) {kwast = new SolidBrush( s.Penkleur ); } Brush kwast ;

Schets-tools (3) ISchetsTool TekstTool Startpunt Tool class TekstTool : StartpuntTool { } override void Letter ( SchetsControl s, char c) { } Graphics g = s. MaakBitmapGraphics(); g. DrawString( c, kwast,..., startpunt ); startpunt.x += ……c….Width; override void MuisDrag ( SchetsControl s, Point p) { } override void MuisLos ( SchetsControl s, Point p) { }

Schets-tools (4) ISchetsTool TekstTool Tweepunt Tool Startpunt Tool abstract class TweepuntTool : StartpuntTool { } override void MuisDrag ( SchetsControl s, Point p) { } Graphics g = s. CreateGraphics(); this. Bezig (g, startpunt, p); abstract void Bezig (Graphics g, Point p1, Point p2) ; override void MuisLos ( SchetsControl s, Point p) { Graphics g = s. MaakBitmapGraphics(); this. Compleet (g, startpunt, p); } virtual void Compleet (Graphics g, Point p1, Point p2) { this. Bezig (g, p1, p2); }

Schets-tools (5) Tool Rechthoek Tool TekstTool Tweepunt Tool Startpunt Tool class RechthoekTool : TweepuntTool { } override void Bezig ( Graphics g, Point p1, Point p2 ) g. DrawRectangle(kwast, Punten2Rechthoek(p1,p2) ); { } static Rectangle Punten2Rechthoek(Point p1, Point p2) { } return new Rectangle( new Point( Math.Min(p1.X,p2.X), Math.Min(p1.Y,p2.Y)) new Size ( Math.Abs(p1.X-p2.X), Math.Abs(p1.Y-p2.Y)) );

Schets-tools (6) Tool TekstTool Tweepunt Tool Startpunt Tool class VolRechthoekTool : RechthoekTool { } override void Compleet ( Graphics g, Point p1, Point p2 ) { } Rechthoek Tool VolRechth Tool g. FillRectangle(kwast, Punten2Rechthoek(p1,p2) );

Schets-tools (7) Tool LijnToolTekstTool Tweepunt Tool Startpunt Tool class LijnTool : TweepuntTool { } override void Bezig ( Graphics g, Point p1, Point p2 ) { } g. DrawLine( MaakPen(kwast,3), p1, p2 ); Rechthoek Tool VolRechth Tool

Schets-tools (8) Tool LijnToolPenToolTekstTool Tweepunt Tool Startpunt Tool class PenTool : LijnTool { } override void MuisDrag ( SchetsControl s, Point p ) { } this. MuisLos (s, p); this. MuisVast (s, p); Rechthoek Tool VolRechth Tool

Schets-tools (9) Tool LijnTool PenToolGumTool TekstTool Tweepunt Tool Startpunt Tool class GumTool : PenTool { } override void Bezig ( Graphics g, Point p1, Point p2 ) { } Rechthoek Tool VolRechth Tool g. DrawLine( MaakPen(Brushes.White,7), p1, p2 );