Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Writing Files3-2-2011Opening DiscussionMinute essay comments:Why are Mondays so awful?Why use an Iterator if it gets consumed after one use?Starting to see the power of Scala.Solutions to the interclass problem.java.util.ScannerJava Scanner class sometimes easier for input.hasNext(), next()hasNextInt(), nextInt()hasNextDouble(), nextDouble() ...Doesn't produce a Scala collection.Needs java.io.File: new Scanner(new File(fileName))Always make a new object from the Java libraries using new. Scala typically allows you to leave that off.Closing FilesMake sure you always close files when you are done using them.Source, Scanner, and pretty much anything else that pulls from a file will have a close() method.java.io.PrintWriterTo write to files use java.io.PrintWriter.Create with new PrintWriter(fileName)Has print and println methods just like what you have been using to print to screen.FlushTo make certain contents have been written to the file use flush().Doing close() will also flush and you should definitely remember to close all files you are writing when done with them.Command Line ArgumentsIn a script, the command line arguments are put in args:Array[String].You can do anything with them that you would do with a normal array.ExamplesPrint some random numbers to a file.A file copy with word replace.Minute EssayHave any questions?What can I do that would help you with the material? Are you reading and trying to do exercises and other things from the


View Full Document

TRINITY CSCI 1320 - Writing Files

Documents in this Course
Functions

Functions

10 pages

Functions

Functions

10 pages

Graphics

Graphics

10 pages

Graphics

Graphics

11 pages

Loops

Loops

4 pages

Loops

Loops

3 pages

Strings

Strings

9 pages

Functions

Functions

10 pages

Loops

Loops

11 pages

Graphics

Graphics

11 pages

Graphics

Graphics

12 pages

Sorting

Sorting

11 pages

Sorting

Sorting

10 pages

Arrays

Arrays

10 pages

Loops

Loops

18 pages

Load more
Download Writing Files
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Writing Files and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Writing Files 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?