Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Writing Files3-2-2011Opening DiscussionMinute 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.ScannerJava 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 FilesMake 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.PrintWriterTo 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.FlushTo 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 ArgumentsIn 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.ExamplesPrint some random numbers to a file.A file copy with word replace.Minute EssayHave 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