Tutorial06 - Tutorial #6: Files OPTIONAL Introduction: This...

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

View Full Document Right Arrow Icon
Tutorial #6: Files O P T I O N A L Introduction: This tutorial is recommended if you have limited experience using file input and output. Note that the programs shown here are available from the textbook website, but it is recommended that you type them in. This will make you more familiar with minor syntax issues such as “throws Exception”. 1. Enter the following code into a program and execute it. It should create a text file and write some student names and scores as shown in your textbook. public class WriteData { public static void main(String[] args) throws Exception { // Create a text file java.io.File file = new java.io.File("scores.txt"); java.io.PrintWriter output = new java.io.PrintWriter(file); // Write formatted output to the file output.print("John T Smith "); // Note the space at the end output.println(90); output.print("Eric K Jones "); // Note the space at the end output.println(85); // Close the file output.close(); } } 2. Use DrJava or another text editor to open the file
Background image of page 1

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

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

Page1 / 2

Tutorial06 - Tutorial #6: Files OPTIONAL Introduction: This...

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

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