SlideServe
Menu
Préférences
© SlideServe · v2026

ECE 122

nixie avatar
10 diapositives · 318 Views · Oct 02, 2014

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.

ECE 122 - slide 1
01 / 10ECE 122
1 / 17

Télécharger la présentation

ECE 122
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. ECE 122 April 14, 2005

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

  3. 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)

  4. Character Stream • Handling input and output of characters • Reader abstract class defines input • Writer abstract class defines output

  5. Console input using Character Streams • BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); • Str = br.readLine(); • Need to catch IOException • Demo ReadLines.java

  6. Console output using Character Streams • PrintWriter(OutputStream os, boolean flushOnNewline) • PrintWriter(System.out, true); • pw.println(something); • Demo PrintWriterDemo.java

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

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

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

  10. Two dimensional array • int table[][] = new int[3][2];//declare • table[0][1] = 15;//assignment • Demo TwoD.java