ece 122
Download
Skip this Video
Download Presentation
ECE 122

Loading in 2 Seconds...

play fullscreen
1 / 10

ECE 122 - PowerPoint PPT Presentation


  • 145 Views
  • Uploaded on

ECE 122. April 14, 2005. I/O stream. Java performs I/O through streams. A stream is linked to a physical device by the Java I/O system. All stream behave in the same manner, even if the actual physical device is different. Same I/O classes and methods apply to any physical device.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' ECE 122' - nixie


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
ece 122

ECE 122

April 14, 2005

i o stream
I/O stream
  • Java performs I/O through streams.
  • A stream is linked to a physical device by the Java I/O system.
  • All stream behave in the same manner, even if the actual physical device is different.
  • Same I/O classes and methods apply to any physical device.
  • Java.io package
byte stream
Byte Stream
  • Handling input/output of bytes
  • InputStream abstract class defines input
  • OutputStream abstract class defines output
  • Example:

System.in (console input from keyboard)

System.out (console output to the screen)

character stream
Character Stream
  • Handling input and output of characters
  • Reader abstract class defines input
  • Writer abstract class defines output
console input using character streams
Console input using Character Streams
  • BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  • Str = br.readLine();
  • Need to catch IOException
  • Demo ReadLines.java
console output using character streams
Console output using Character Streams
  • PrintWriter(OutputStream os, boolean flushOnNewline)
  • PrintWriter(System.out, true);
  • pw.println(something);
  • Demo PrintWriterDemo.java
file output using filewriter
File output using FileWriter
  • FileWriter(String filename, boolean append) throws IOException
  • fw = new FileWriter(“test.txt”, false);
  • fw.write(string);
  • fw.close();
  • Demo KtoD.java, a utility that convert keyboard input to disk.
file input using filereader
File Input using FileReader
  • FileReader(String filename) throws FileNotFoundException
  • FileReader fr = new FileReader(“test.txt”);
  • BufferedReader br = new BufferedReader(fr);
  • br.readLine();
  • fr.close();
  • Demo DtoS.java, a utility that read data from disk and print to screen
one dimensional array
One dimensional Array
  • We have introduced one-dimensional array in our previous lectures.
  • An array is a collection of variables of the same type, referred by a common name.
  • type array-name [] = new type[size];
  • int age[] = new int[5];//declaration
  • age[0] = 20;//assignment
  • Animal animal [] = new Animal[1000];//declare
  • animal[0] = new Animal();//creation & assignment
  • Array length: age.length, animal.length
two dimensional array
Two dimensional array
  • int table[][] = new int[3][2];//declare
  • table[0][1] = 15;//assignment
  • Demo TwoD.java
ad