0% found this document useful (0 votes)
34 views2 pages

Java Practice Session 5: File and Network Programming

This two day training session covers working with streams, files, and networking in Java. Topics include using ByteArrayOutputStream and ByteArrayInputStream to write and read bytes, implementing character counting Reader and Writer classes, using the File class to check for files, create/delete files, and get file listings, reading and writing files using FileReader and FileWriter, modifying file contents using a custom character replacing FilterReader, using RandomAccessFile to concatenate files into an archive file and extract individual files, and using Sockets to connect to an SMTP server and send emails.

Uploaded by

crucifixio4690
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Java Practice Session 5: File and Network Programming

This two day training session covers working with streams, files, and networking in Java. Topics include using ByteArrayOutputStream and ByteArrayInputStream to write and read bytes, implementing character counting Reader and Writer classes, using the File class to check for files, create/delete files, and get file listings, reading and writing files using FileReader and FileWriter, modifying file contents using a custom character replacing FilterReader, using RandomAccessFile to concatenate files into an archive file and extract individual files, and using Sockets to connect to an SMTP server and send emails.

Uploaded by

crucifixio4690
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

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
java.io.* %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 java.io 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 java.io.File 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 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

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 =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.

You might also like