Java Practice Session 5 File and network programming
Duration: 2 days Software: J2SDK 1.5, IntelliJ IDEA
Description
This session is dedicated to workin with I!" strea#s, $iles and networkin .
Documentation
[Link].* %acka e API Note: 0e are not (sin 12ew I3!45
To%ic 1" Basic I/O using Streams
Goal: &a#iliari'e yo(rsel$ with [Link] classes API Tasks: 1. )sin ByteArrayOutputStream a. *reate a +yte array 1,, +ytes lon +. *reate ByteArrayOutputStream and write this array into the strea# c. -etrieve res(ltin array
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.
To%ic 2" Files and networking
Goal: )nderstand how to access $iles and trans$er data via network Tasks: 1. )se [Link] instance to" a. *heck i$ a certain $ile e/ists +. *reate it i$ it does not c. Delete it i$ it does and re7create new one
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 [Link] 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
re%laced with another 8e. .
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 =[Link].-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 =[Link] 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.