Java I/O and Java Networking Yoshi. Recall that…

Slides:



Advertisements
Similar presentations
Jan Java I/O Yangjun Chen Dept. Business Computing University of Winnipeg.
Advertisements

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.
III. Streams. Introduction Often a program needs to bring in information from an external source or to send out information to an external destination.
: Arrange the Numbers ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11481: Arrange the Numbers 解題者:李重儀 解題日期: 2008 年 9 月 13 日 題意: 將數列 {1,2,3, …,N}
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.
走過生命中的轉彎處 從心出發. 這次的宣傳海報 首先由馬副校長來致詞 充滿元氣的謝坤山先生, 開朗的笑聲,讓全場都 感受到他的活力。
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
YOSHI Package and Import. 加油 ! 陳欣怡 ! 世界上有多少陳欣怡 ? 2004 的大學聯考,榜單上叫「陳怡君」的,總共有 64 人,有些人考上了好學校,有些卻名落孫山,同樣 姓名卻有不一樣的際遇。 雅婷.勝.
Network Read/Write. Review of Streams and Files java.io package InputStream and OutputStream classes for binary bytes Reader and Writer classes for characters.
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
Java I/O and Java Networking (Client Side) Yoshi.
Unit 201 FILE IO Types of files Opening a text file for reading Reading from a text file Opening a text file for writing/appending Writing/appending to.
Introduction to Java Programming Lecture 15 Objects and Classes.
奇怪的隱形人 ---- 微中子簡介 An Introduction to Neutrino High School Seminar at NTHU July 9, 2007 張維甫 We-Fu Chang.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
-Antidifferentiation- Chapter 6 朝陽科技大學 資訊管理系 李麗華 教授.
生涯規劃與發展 羅寶鳳. 我的志願 很小的時候,爸爸曾經問我,你長大 後要做什麼? 我一手拿著玩具,一手拿著糖果,我 長大後要做總統。 六年級的時候,老師也曾問我,你長 大後要做什麼? 愛迪生的故事,最讓我佩服,我長大 要做科學家。
1 Introduction to Java Programming Lecture 6 Program Input : BufferedReader & Scanner.
CS102--Object Oriented Programming Lecture 14: – File I/O BufferedReader The File class Write to /read from Binary files Copyright © 2008 Xiaoyan Li.
Chapter 91 Streams and File I/O CS-180 Recitation-03/07/2008.
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 ->
輸入輸出設備. 檔案 Outline java.io.File 類別 檔案類別串流 java.io.RandomAccessFile 類別.
7/2/2015CS2621 OO Design and Programming II I/O: Reading and Writing.
What is static? CS340100, NTHU Yoshi. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1;
著作權所有 © 旗標出版股份有限公司 第 14 章 製作信封、標籤. 本章提要 製作單一信封 製作單一郵寄標籤.
Exceptions and IO Dr. Andrew Wallace PhD BEng(hons) EurIng
Java File I/O (Continued). File I/O in Java Like every other programming language, Java supports the writing to and reading from different files with.
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.
Prepared by : A.Alzubair Hassan Kassala university Dept. Computer Science Lecture 2 I/O Streams 1.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
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.
Based on OOP with Java, by David J. Barnes Input-Output1 The java.io Package 4 Text files Reader and Writer classes 4 Byte stream files InputStream, FileInputStream,
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
File IO Basics By Dan Fleck Coming up: Data Streams.
Two Ways to Store Data in a File  Text format  Binary format.
! !美洲華語 李雅莉老師製作 TextVocabularyidiomStoryChallenge $100 $200 $300 $400 $500 $600 $100 $200 $300 $400 $500 $600 $100 $200 $300 $400 $500 $600 $100 $200.
CIS 270—App Dev II Big Java Chapter 19 Files and Streams.
CS101 Lab “File input/Output”. File input, output File : binary file, text file READ/WRITE class of “text file” - File Reading class : FileReader, BufferedReader.
5-Dec-15 Sequential Files and Streams. 2 File Handling. File Concept.
CIS Intro to JAVA Lecture Notes Set 6 2-June-05.
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.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
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.
 Learn about computer files  Use the Path class  Learn about  Streams  Buffers  file organization  Use Java’s IO classes to write to and read from.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
! !美洲華語 李雅莉老師製作 TextVocabularyusageStoryChallenge $100 $200 $300 $400 $500 $600 $100 $200 $300 $400 $500 $600 $100 $200 $300 $400 $500 $600 $100 $200.
設問. 學習室 你們記得甚麼是 設問嗎? 學習室 設問是提出問題 後,接着就説出 答案。其實作者 心中早有答案, 不用對方回答。
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.
CSC1351 Class 6 Classes & Inheritance.
Keerthi Nelaturu Url: site.uottawa.ca/~knela006
十月一日是國慶 qing\ 節。 Level 2 第一課 開學 New exercises online Character analysis Character differentiation.
OO Design and Programming II I/O: Reading and Writing
Lec 06 David Presentation on Advanced Spring
CHAPTER 5 JAVA FILE INPUT/OUTPUT
I/O Basics.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
JAVA IO.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
Input and Output Stream
Web Design & Development Lecture 8
Streams and Readers The stream hierarchy is for reading bytes, the reader/writer hierarchy is for reading characters Unicode characters can be used internationally,
Presentation transcript:

Java I/O and Java Networking Yoshi

Recall that…

Murmur…  張無忌只花了幾個時辰就學會了別人要學好幾 年的乾坤大挪移,為什麼 ?  因為張無忌有深厚的九陽神功 !  Decorator pattern & other patterns  九陽神功 ( 內功 )  Java I/O  乾坤大挪移 ( 外功 )  光學會內功,不懂得外功仍舊無太大用途  覺遠大師即為一例  光會外功,內功薄弱  令狐沖,但是他後來還是靠了吸星大法和易筋經

RTFSC  Please see IOExample.zipIOExample.zip  Exercise  Write your own input/output filters which encrypt/decrypt the stream data  For example: a simple encryption  I love you  J mpwf zpv (shift 1)  Write your own writer filter which makes 中文字 to 注音文  For example  我也不知道啊, 呵呵  我也ㄅㄓ道ㄚ, ㄏㄏ

Stream Concept Input Stream Output Stream

Character Stream  The Java platform stores character values using Unicode conventions. Character stream I/O automatically translates this internal format to and from the local character set.  Character streams are often wrappers for byte streams. The character stream uses the byte stream to perform the physical I/O, while the character stream handles translation between characters and bytes.  FileReader  FileInputStream  FileWriter  FileOutputStream

Line-Oriented public class CopyLines { public static void main(String[] args) throws IOException { BufferedReader inputReader = null; PrintWriter outputWriter = null; try { inputReader = new BufferedReader(new FileReader(“input.txt")); outputWriter = new PrintWriter(new FileWriter("output.txt")); String line; while ((line = inputReader.readLine()) != null) { outputWriter.println(line); } finally { if (inputReader != null) { inputReader.close(); } if (outputWriter != null) { outputWriter.close(); }

Let’s see the 注音文 filter

java.net.Socket  This class implements client sockets (also called just "sockets").  A socket is an endpoint for communication between two machines.  Very similar to local I/O operations

Retrieve Yahoo! Homepage import java.io.*; import java.net.*; public class RetrieveWeb { public RetrieveWeb(String host, int port) throws IOException { Socket socket = new Socket(host, port); InputStream in = socket.getInputStream(); BufferedReader reader = new BufferedReader( new InputStreamReader(in, "UTF8")); OutputStream out = socket.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out)); pw.println("GET /"); pw.flush(); String line=""; while( (line=reader.readLine()) != null) { System.out.println(line);

Retrieve Yahoo! Homepage } reader.close(); pw.close(); } public static void main(String[] args) throws IOException { //delete the following three lines to make this program general args = new String[2]; args[0] = "tw.yahoo.com"; args[1] = "80"; int port = Integer.parseInt(args[1]); RetrieveWeb obj = new RetrieveWeb(args[0], port); }

Something strange?  java.io.InputStream java.io.InputStream  public abstract int read() throws IOException  java.io.OutputStream  public abstract void write(int b) throws IOException

Something strange? (2)  byte  -128 ~ +127  -1 implies end of stream  a-io-stream-read-write.html a-io-stream-read-write.html  You can also find it in O’Reilly Java I/O

Exercise  Trace java.io.BufferedReader  edReader.java.html edReader.java.html  Write a program to connect to hulabear.twbbs.org:23