1 Prototyping for HCI Spring 2004 (Week 9) Jorge A. Toro.

Slides:



Advertisements
Similar presentations
Introduction to File I/O How to read & write data to a disk file...
Advertisements

Lecture 27: FILE HANDLING in C Language FILE HANDLING in C Language-2 Lecture 27.
Reading and Writing Text Files Svetlin Nakov Telerik Corporation
Practical Programming COMP153-08S Lecture: Repetition Continued.
Lecture Roger Sutton CO331 Visual Programming 19: Simple file i/o Exceptions – Error handling 1.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
1 Prototyping for HCI Spring 2004 (Week 7) Jorge A. Toro.
Chapter 9: Sequential Access Files and Printing
1 Prototyping for HCI Spring 2004 (Week 10) Jorge A. Toro.
File dialog boxes Function args and overloading. Examples in this show List directory contents Open a file for viewing Read/Write to a file Add file I/O.
1 Prototyping for HCI Spring 2004 (Week 8) Jorge A. Toro.
Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.
Additional loop presentation
Introduction to Structured Query Language SQL. SQL Select Command SELECT * FROM tableName WHERE criteria;
Chapter 8 - VB.Net by Schneider1 Chapter 8 – Sequential Files 8.1 Sequential Files Creating a Sequential File Adding Items to a Sequential File Error Trapping.
Input/Output CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Visual C Sharp – File I/O - 1 Variables and arrays only temporary - lost when a program terminates Files used for long term storage (Data bases considered.
File Handling. Data Files Programs that can only get data from the user interface are limited. –data must be entered each time. –only small amounts of.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
November 15, 2005ICP: Chapter 7: Files and Exceptions 1 Introduction to Computer Programming Chapter 7: Files and Exceptions Michael Scherger Department.
Using Arrays and File Handling
Processing Lists of Data with Do Loops (Examples)
1 Text Files Managing Text Files StreamReaders, StreamWriters, ReadAllLines, and WriteAllLines Method The OpenFileDialog Control Structured Exception Handling.
Chapter 8 - VB 2008 by Schneider1 Chapter 8 – Sequential Files 8.1 Sequential Files 8.2 Using Sequential Files.
File I/O Static void Main( ) {... } data. Topics I/O Streams Reading and Writing Text Files Formatting Text Files Handling Stream Errors File Pointers.
Creating Sequential Files, Adding Data, & Deleting Data.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
1 COMP3100e Developing Microsoft.Net Applications for Windows (Visual Basic.Net) Class 6 COMP3100E.
File I/O What We’ll Cover –Visual Basic Techniques for Text Files –.NET Techniques for Text Files What We’ll Not Cover –Binary File I/O –XML File I/O.
Tutorial 9: Sequential Access Files and Printing1 Tutorial 9 Sequential Access Files and Printing.
INPUT AND OUTPUT 1. OUTPUT TextBoxes & Labels MsgBox Function/Method MessageBox Class Files (next topic) Printing (later) 2.
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.
Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
CSC 298 Streams and files.
File IO.  File Input/Output  StreamWriter  StreamReader  Text Files  Binary Files.
BACS 287 File-Based Programming. BACS 287 Data Hierarchy  Database - Collection of files, relationships, integrity information, etc  Files - All records.
CS 4 Intro to Programming in Visual Basic Files and Loops (2) Patchrawat Uthaisombut University of Pittsburgh 1.
Error Trapping Exception Catching 1. Syntax & Compile-time  VB – Editor/Compiler Logic and Design  You Runtime  You Types of Errors: 2 When your program.
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.
Chapter 6 - VB 2008 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study: Analyze a Loan.
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)
File I/O. I/O Flags Flags are passed to give some information about how the file is to be used. – Read only file – flag=0x0 – Write only file – flag=0x1.
Test1 Here some text. Text 2 More text.
INPUT AND OUTPUT.
Reading & writing to files
Ch 10 Sequential Access Files
Chapter 8 – Sequential Files
Files and Streams Lect3 CT1411.
File Input/Output (I/O)
[type text here] [type text here] [type text here] [type text here]
Variable Review & IO User 12/26/2018.
Your text here Your text here Your text here Your text here Your text here Pooky.Pandas.
Chapter 3.5 Input and Output
Input and Output.
Tutorial 9 Sequential Access Files and Printing
Your text here Your text here Your text here Your text here
Chapter 6 - VB.Net by Schneider
[type text here] [type text here] [type text here] [type text here]
Lecture 16 File I/O Richard Gesick.
Introduction to Programming Lecture 6
Input and Output.
Input and Output Chapter 3.5
Lecture 18 File I/O CSE /5/2019.
Presentation transcript:

1 Prototyping for HCI Spring 2004 (Week 9) Jorge A. Toro

2 The Language File I/O

HCI430 – J.Toro3 File I/O Here, we will deal with text files only. In VB.NET, different classes handle different aspects of text files.  One class deals with reading files  One class deals with writing into files  Etc…

HCI430 – J.Toro4 File I/O IO.StreamReader class  Objects of this class are capable of reading text files IO.StreamWriter class  Objects of this class are capable of writing into text files

HCI430 – J.Toro5 File I/O IO.StreamReader class  Used for reading text files. Dim sr As IO.StreamReader sr = IO.File.OpenText(“hello.txt”) The object sr is created and opened the file “hello.txt” for reading

HCI430 – J.Toro6 File I/O If the file does not exist, you get an exception You need to “trap” the exception so the program does not fail.  There are different exceptions for different errors

HCI430 – J.Toro7 File I/O Reading text from the file  ReadLine method Reads one complete line of text from the file  Read method Reads at least one character from the file

HCI430 – J.Toro8 File I/O How do I know I finished reading a file?  Use the Peek method in the StreamReader  Peek returns -1 it you reached the end of the file

HCI430 – J.Toro9 File I/O Assume that there is a text file with the following format: id1 Last name1 First name1 Address1 City1 State1 Zip1... idN Last nameN First nameN AddressN CityN StateN ZipN

HCI430 – J.Toro10 File I/O Let’s traverse the file and display it into a textbox with multilines

HCI430 – J.Toro11 File I/O Dim sr As IO.StreamReader = IO.File.OpenText("members.txt") While sr.Peek <> -1 s = sr.ReadLine textbox1.text = textbox1.text & s End While sr.Close()

HCI430 – J.Toro12 File I/O IO.StreamWriter class  Used for writing into text files. Dim sr As IO.StreamWriter sr = IO.File.CreateText(“hello.txt”) The object sr creates a new file (“hello.txt”) for writing Dim sr As IO.StreamWriter sr = IO.File.AppendText(“hello.txt”) The object sr opens a file (“hello.txt”) for appending text to it

HCI430 – J.Toro13 File I/O Writing text into the file  WriteLine method Writes one complete line of text in the file and attaches a (character 13) at the end of it  Write method Writes at least one character in the file but does not attach a

HCI430 – J.Toro14 File I/O Important!!  Make sure you call the Close method after you are done using the file. Dim sr As IO.StreamReader = IO.File.OpenText("members.txt") While sr.Peek <> -1 s = sr.ReadLine textbox1.text = textbox1.text & s End While sr.Close() sr now closes the file