CS2_26_FileIO_Streams

CS2_26_FileIO_Streams - CS2 Module 26 Category: Elements of...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2 Module 26 Category: Elements of Java Topic: Input/Output Objectives Basic I/O Streams
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 2 Introduction to Object Oriented Programming Module 26 Elements of Java Input Output
Background image of page 2
Printing to Screen CS1: (display <argument>) Java: System.out.println(<argument>); System.out.println( ); // prints blank line System.out.println(5); // prints 5 System.out.println("Hello World"); // prints Hello World "println" vs. "print" in Java: println includes "carriage return" at end, next print or println on new line print causes next print or println to begin at next location on same line Quick Review
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Printing to Screen String concatenation in Java is accomplished using "+" Use of "+" will often appear in print and println parameter lists. System.out.println("Average is " + avgScore); System.out.print("This is another handy " + "use of the concatenation operator " + "when the line is just too long, " + "you can break " + "it up this way…"); Quick Review
Background image of page 4
Printing to Screen Recall that Java has two predefined output streams. System.out System.err In this course use System.out avoid System.err. System.err is used by the autograders. Quick Review
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java I/O: Fun with Streams In general, there are streams inherent in any Java process: System.in System.out System.err You are already familiar with most of these streams. E.g., System.out.println(“This is the output stream”); System.err.println(“Something went wrong!”);
Background image of page 6
Java I/O Today we’ll see how we can do several types of reading: read from standard input (the keyboard) open a file and read from it. even open a web URL and read from it!!! Amazingly all three of these be accomplished with a class called java.io.BufferedReader
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java I/O We’ll also see how to write output: How to output to the screen we’ve been using System.out.print How to output to a file using a class called java.io.BufferedWriter
Background image of page 8
But First This is the world of your computer program This is the outside world
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
But First This is the world of your computer program This is the outside world Keyboard Disk File Disk File WWW
Background image of page 10
But First This is the world of your computer
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

CS2_26_FileIO_Streams - CS2 Module 26 Category: Elements of...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online