Web Design & Development Lecture 8

Slides:



Advertisements
Similar presentations
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
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.
Jan Java I/O Yangjun Chen Dept. Business Computing University of Winnipeg.
Introduction to Java 2 Programming Lecture 7 IO, Files, and URLs.
Lecture 15: I/O and Parsing
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Streams Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Java I/O The Cheat Sheet. Reading and Writing The basic architecture of Java IO is pluggable. The idea is to have some very simple classes do very simple.
III. Streams. Introduction Often a program needs to bring in information from an external source or to send out information to an external destination.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
James Tam Simple file handling in Java Simple File Input And Output Types of Java files Simple file output in Java Simple file input in Java.
Network Read/Write. Review of Streams and Files java.io package InputStream and OutputStream classes for binary bytes Reader and Writer classes for characters.
Java I/O and Java Networking (Client Side) Yoshi.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
פיתוח מונחה עצמים – שפת JAVA קבצים. References קורס "שיטות בהנדסת תוכנה", הפקולטה למדעי המחשב, הטכניון. קורס "מערכות מידע מבוזרות", הפקולטה להנדסת תעשייה.
Java I/O Input: information brought to program from an external source
CIS 068 JAVA I/O: Streams and Files. CIS 068 I/O Usual Purpose: storing data to ‘nonvolatile‘ devices, e.g. harddisk Classes provided by package java.io.
Two Ways to Store Data in a File Text format Binary format.
5-Oct-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Streams and Files Maj Joel Young.
Very Brief Introduction to Java I/O with Buffered Reader and Buffered Writer.
Prepared by : A.Alzubair Hassan Kassala university Dept. Computer Science Lecture 2 I/O Streams 1.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
The Java I/O Classes and Interfaces cont’d
File IO Basics By Dan Fleck Coming up: Data Streams.
By Rachel Thompson and Michael Deck.  Java.io- a package for input and output  File I/O  Reads data into and out of the console  Writes and reads.
Two Ways to Store Data in a File  Text format  Binary format.
CS101 Lab “File input/Output”. File input, output File : binary file, text file READ/WRITE class of “text file” - File Reading class : FileReader, BufferedReader.
Lecture 5 I/O and Parsing
Read and Write Files  By the end of this lab you will be able to:  Write a file in internal storage  Read a file from internal storage  Write a file.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
Exception Handling, Reading and Writing in Files, Serialization, Exceptions, Files, Streams, File Readers and Writers, Serializable SoftUni Team Technical.
Java Input/Output. Java Input/output Input is any information that is needed by your program to complete its execution. Output is any information that.
1 Putting Streams to use. 2 Stream Zoo C++ gives you istream, ostream, iostream, ifstream, ofstream, fstream, wistream, wifstream, istrsteam… (18) Java.
Java Input / Output l a modular approach to input/output: - different stream objects are connected/wrapped to handle I/O l a data stream object: a flow.
Java I/O 1. Java I/O (Input and Output) is used to process the input and produce the output based on the input. The java.io package contains all the classes.
CS 116 Object Oriented Programming II Lecture 11 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
CS202 Java Object Oriented Programming Input and Output Chengyu Sun California State University, Los Angeles.
java.io supports console and file I/O
The Java IO System Different kinds of IO Different kinds of operations
CSC1351 Class 6 Classes & Inheritance.
Keerthi Nelaturu Url: site.uottawa.ca/~knela006
IO in java.
Lecture 8: I/O Streams types of I/O streams Chaining Streams
Java Text I/O CS140 Dick Steflik. Reader Abstract super class for character based input Subclasses: – BufferedReader – CharArrayReader – FilterReader.
Exception Handling, Reading and Writing in Files, Serialization,
OO Design and Programming II I/O: Reading and Writing
Lesson 8: More File I/O February 5, 2008
University of Central Florida COP 3330 Object Oriented Programming
Program Input/Output (I/O)
Java Exceptions and I/O
12: The Java I/O System stream model.
CHAPTER 5 JAVA FILE INPUT/OUTPUT
I/O Basics.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
JAVA IO.
הרצאה 12: קבצים וחריגות (Exceptions)
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
CHAPTER 5 (PART 2) JAVA FILE INPUT/OUTPUT
“Introduction to Programming With Java”
Reading and Writing Text Files
Files and Streams in Java
Java Basics Introduction to Streams.
File Input and Output.
ECE 122 April 14, 2005.
Java IO Packages Prepared by Mrs.S.Amudha AP/SWE
David Davenport Spring 2005
Presentation transcript:

Web Design & Development Lecture 8

Streams

Why Streams?

Node Streams Node Stream

Filter Streams Filter Stream

Filter Streams 10100011 11001100 Byte Stream

Character Streams also known as Reader / Writer Filter Streams A H D E Character Streams also known as Reader / Writer

Character vs. Byte Streams A character stream manages 16-bit Unicode characters A byte stream manages 8-bit bytes of raw binary data A program must determine how to interpret and use the bytes in a byte stream Typically they are used to read and write sounds and images The InputStream and OutputStream classes (and their descendants) represent byte streams The Reader and Writer classes (and their descendants) represent character streams

Types of Streams InputStream / OutputStream Base class streams with few features read() and write() FileInputStream / FileOutputStream Specifically for connecting to files ByteArrayInputStream / ByteArrayOutputStream Use an in-memory array of bytes for storage! BufferedInputStream / BufferedOutputStream Improve performance by adding buffers Should almost always use buffers BufferedReader / BufferedWriter Convert bytes to unicode Char and String data Probably most useful for what we need

Reading from File

Reading From File Hello World Pakistan is our homeland Web Design and Development input.txt

ReadFile. java /* This program reads file line by line and prints them on to the console */ import java.io.*; public class ReadFile { public static void main (String args[ ]) { FileReader fr = null; BufferedReader br = null; try { fr = new FileReader("input.txt"); br = new BufferedReader(fr); //continue

ReadFile. java String s = br.readLine(); while (s != null) { System.out.println(s); s = br.readLine(); } br.close(); fr.close(); } catch (IOException ex) { System.out.println(ex); }// end of main }//end of class

Compile & Execute

Writing into File

WriteFile. java // This program writes the strings into the file “output.txt” import java.io.*; public class WriteFile { public static void main (String args[ ]) { FileWriter fw = null; PrintWriter pw = null; try { // if file does not exist, it automatically create for you fw = new FileWriter("output.txt"); pw = new PrintWriter(fw); //continue..

WriteFile. java String s1 = "Hello World"; String s2 = "Web Design and Development"; pw.println(s1); pw.println(s2); pw.flush(); pw.close(); fw.close(); } catch (IOException ex) { System.out.println(ex); } }//end of main }//end of class

Compile & Execute Hello World Web Design and Development output.txt

Why Streams

Reading Data from File BufferedReader br = new BufferedReader (fr); FileReader fr = new FileReader(“input.txt”); BufferedReader br = new BufferedReader (fr); Console FileReader fr = new FileReader(FileDescriptor.in); Network InputStream is = s.getInputStream() ; BufferedInputStream br = new BufferedInputStream (is) ; //where “s” is the socket

Writing Data to File PrintWriter pw = new PrintWriter (pw); Console FileWriter fw = new FileWriter(“output.txt”); PrintWriter pw = new PrintWriter (pw); Console FileWriter fw = new FileWriter(FileDescriptor.out); PrintWriter pw = new PrintWriter (fw); Network OutputStream os = s.getOutputStream() ; PrintWriter pw = new PrintWrtier (os) ; //where “s” is the socket

Problem Take input from console Write that input to text file with line numbers Program should only exit when user press enters without typing anything