Java Practice Session 5: File and Network Programming
Java Practice Session 5: File and Network Programming
Description
This session is dedicated to workin with I!" strea#s, $iles and networkin .
Documentation
java.io.* %acka e API Note: 0e are not (sin 12ew I3!45
d. *reate ByteArrayInputSream and read +ytes $ro# res(ltin array e. *o#%are arrays to ens(re nothin .s chan ed 2. )sin Reader and Writer
a. I#%le#ent a %air o$ classes, one e/tendin Reader and one e/tendin Writer, that co(nt the n(#+er o$ ti#es a %artic(lar character, s(ch as e, is read or written. +. The character can +e s%eci$ied when the strea# is created. c. 0rite a %ro ra# to test yo(r classes.
Version 1.0
Java Practice Session 1" 5" File a!a and Basics network programming
StarSoft Develo%#ent 6a+s, Inc.
d. Print list o$ all $iles in a certain directory e. Print list o$ Java so(rce $iles in a certain directory 2. -eadin and writin $iles a. )se java.io.FileReader to read the contents o$ a te/t $ile into char array +. *reate a FilterReader s(+class that re%laces certain character with another one c. )se this Reader to read contents o$ a $ile with so#e letter 8e. .
q9
w9
d. )se FileWriter to write #odi$ied contents +ack into ori inal $ile e. :odi$y the %ro ra# to read and write short se;(ences o$ chars 8e. . 1,,9 to #ini#i'e #e#ory <. )sin -ando#Access&ile a. )se =ava.io.-ando#Access&ile to concatenate 8>archive.9 all te/t 8?.t/t9 $iles in a directory in a sin le $ile in the $ollowin $or#at file name (zero-ending string file length (long file contents (!"ar#$ +. 2ow write a %ro ra# to e/tract a iven te/t $ile +ack $ro# the archive @. )sin Sockets to send e#ails a. )se =ava.net.Socket to +. *onnect to the S:PT server 8%ort 259 c. Send an e#ail (sin $or#at %&'O sending "ost (AI' FRO() *sender e-mail address+ R,-. .O) *re!ipient e-mail address+ /A.A mail message (any num0er o1 lines . 23I.