1 / 11

Day 48

Day 48. 9.1 An Overview of Streams and File I/O. Upcoming Test. Next Tuesday – test on everything learned related to Inheritance Focus will be on multiple choice and less on coding. The Concept of a Stream. You are already using files to store your Java classes and programs

breena
Download Presentation

Day 48

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Day 48 9.1 An Overview of Streams and File I/O

  2. Upcoming Test • Next Tuesday – test on everything learned related to Inheritance • Focus will be on multiple choice and less on coding

  3. The Concept of a Stream • You are already using files to store your Java classes and programs • You can also use files to store input for a program or to hold output from a program • In Java, file I/O, as well as simple keyboard and screen I/O, is handled by streams

  4. A stream is an object that either delivers data to their destination, such as a file or the screen, or takes data from a source, such as a file or the keyboard, and delivers data to your programs

  5. The object System.out is the only output stream we have used so far • Objects of the class Scanner , which we have been using for keyboard input, are streams

  6. A stream is a flow of data (characters, numbers or bytes consisting of binary digits) • If the data flow into your program, the stream is called an input stream • If the data flow out of your program … (for heaven’s sake, fill in the blanks)

  7. Differences between Text Files and Binary Files • Files that you write and read using an editor are called text files (aka ASCII files as they contain data encoded using a scheme known as ASCII coding) • Binary files represent data in a way that is inconvenient to read with a text editor but can be written and ready by a program very efficiently

  8. 9.2 Text-File I/O • PrintWriteris the preferred stream class for writing to a text file • The first line of your code should be importjava.io.*; • This tells Java you will be using the java.io library

  9. The file is created by writing outputStream = newPrintWriter(newFileOutputStream(“fileName.txt”);

  10. TIME TO CODE…

  11. Exercise WARNING: this may be hard Create a word search puzzle with the following conditions • The puzzle is 10x10 • Each character is created by the math class’s randomization feature (search it up) • Each character in the puzzle is also stored in a 2-D array • After the puzzle is generated, insert words relevant to this unit (along the vertical, horizontal and diagonal and make some intersect) • Print out the word search to a txt file

More Related