Introduction to Programming Gordon College Streams.
-
date post
22-Dec-2015 -
Category
Documents
-
view
226 -
download
0
Transcript of Introduction to Programming Gordon College Streams.
![Page 1: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/1.jpg)
Introduction to Programming
Gordon College
Streams
![Page 2: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/2.jpg)
Psal 1:1 Blessed is the man who does not walk in the counsel of the wicked or stand in the way of sinners or sit in the seat of mockers. But his delight is in the law of the LORD, and on his law he meditates day and night. He is like a tree planted by streams of water, which yields its fruit in season and whose leaf does not wither. Whatever he does prospers.
![Page 3: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/3.jpg)
ffd8ffe000104a464946000101000100010000ffdb00430006
Stream.jpg
Camera to file
![Page 4: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/4.jpg)
ffd8ffe000104a464946000101000100010000ffdb00430006
Stream.jpg
File to Laptop
![Page 5: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/5.jpg)
ffd8ffe000104a464946000101000100010000ffdb00430006
Laptop to Laptop
![Page 6: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/6.jpg)
Outline
Data Hierarchy What’s a Stream Different Types of Streams Text Streams Meta-File Information Binary Files and Random Files Accessing Pages Through a Network
![Page 7: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/7.jpg)
Data Hierarchy
![Page 8: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/8.jpg)
What’s a Stream
Managed flow of data between programs & any external entity that can provide or receive data.
Java stream-processing capabilities:
1. read & write data in files
2. read & write data in memory
3. read & write data over network connections
![Page 9: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/9.jpg)
Different Types of Streams
1. Direction of streamWhich way does the stream flow? input stream - from file to process output stream - from process to file
`
![Page 10: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/10.jpg)
Different Types of Streams
2. Kinds of stream Byte-based streams
Store data in Binary format. Called “binary files”. Data must be converted to a character form before it
is displayed for the user. Character-based streams
Stores the data in Character format. Called “text files”. Also typically has special characters (like \n - which
signifies the end) produced and used by text editors
![Page 11: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/11.jpg)
Different Types of Streams
For Example: Binary Files:
The value 5 is stored in binary format as 101…or more specifically it is stored using an integer format (like 2’s complement) so it would be 000000000000101.
Types: financial files, picture files, program executables etc.
Test Files: The value 5 in character format would be 00000000 00110101 which is the ASCII value for 5 in Unicode format.
Types: text files (.txt), html, xml, etc.
![Page 12: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/12.jpg)
Different Types of Streams
Network Streams
`
Textbook Example: Simple Weather
![Page 13: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/13.jpg)
Text Streams
System.out is a static stream which is automatically open and ready to accept output data:
System.out.print("Enter Date (mm/dd/yyyy): ");
for ( int x= 1; x <= 10; x++) {
date = date + (char) System.in.read();
}
System.in, System.out, System.err. (can be redirected)
Example: Redirection example.
![Page 14: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/14.jpg)
Text Streams
Simple Example - input from the keyboard:
private static String readString() throws IOException
{
String tempS="";
int tempC;
while ((tempC = System.in.read())!='\n')
{
tempS += (char) tempC;
}
return tempS;
}
Example: TextFileMaker1 (example of redirection)
![Page 15: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/15.jpg)
Text Streams
Simple example – input from a file1. Create the input stream object:
BufferedReader input = new BufferedReader(new FileReader(filename));
2. Use readLine
boolean booleanValue = (new Boolean(input.readLine())).booleanValue();
3. Close file
input.close();
See example: TextFileAccessor
![Page 16: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/16.jpg)
Text Streams
Writer
FileWriter PrintWriter
write
write println – independentof the particular stream
PrintWriter file1 = new PrintWriter (new FileWriter(“file.txt” ) );
file1.println(“A line of text”);
![Page 17: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/17.jpg)
Text Streams
read
read readLine – returns nullreference at EOF
BufferedReader file1 = new BufferedReader (new FileReader(“file.txt” ) );
file1.readLine();
Reader
FileReader BufferedReader
![Page 18: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/18.jpg)
Text Streams
Simple example – input from a file1. Create the input stream object:
BufferedReader input = new BufferedReader(new FileReader(filename));
2. Read the linesString curLine = someBufferedReader.readLine();
while(curLine != null) {… curLine = someBufferedReader.readLine();
}3. Close file input.close();
See example: TextFileAccessor
![Page 19: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/19.jpg)
Meta-File Information
What sort of information does a file system contain?
File class - An abstract representation of file and directory pathnames
File name = new File( “filename.dat”);
See examples: FileTest1 & FileTest
![Page 20: Introduction to Programming Gordon College Streams.](https://reader036.fdocuments.net/reader036/viewer/2022062320/56649d805503460f94a652e3/html5/thumbnails/20.jpg)
Meta-File Information
Methods for class
getName()
isFile()
isDirectory()
isAbsolute()
lastModified()
length()
getPath()
getAbsolutePath()
getParent()