From JavaWIDE
|
01 //start auto-imports
02 //end auto-imports
03 importimport means to make the classes and/or packages available in this program java.util.*;
04 importimport means to make the classes and/or packages available in this program java.io.*;
05 importimport means to make the classes and/or packages available in this program java.net.*;
06 /**
07 * A simple application to read text from a file on the wiki.
08 * @authornull Jam Jenkins
09 */
10
11 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects SampleTextFileWriter
12 {open braces start code blocks and must be matched with a close brace
13 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.( String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args )
14 {open braces start code blocks and must be matched with a close brace
15 trytry is for executing a code block that may experience exceptions (errors) //the following code may cause an exception if the file does not exist
16 {open braces start code blocks and must be matched with a close brace
17 //open the input stream using the file name
18 File file =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor File( "SampleOut.txt" );
19 PrintWriter writer =this assignment operator makes the left side equal to the right side newnew is used to create objects by calling the constructor PrintWriter( file );
20 writer.println( "Hello JavaWIDE!" );
21 writer.println( "Hello File Output!" );
22 writer.flush();
23 writer.close();
24 }close braces end code blocks and must match an earlier open brace
25
26 catchcatch means to handle an exception that may occur ( IOException e ) //in case the file does not exist, say so
27 {open braces start code blocks and must be matched with a close brace
28 e.printStackTrace( System.err );
29 }close braces end code blocks and must match an earlier open brace
30 }close braces end code blocks and must match an earlier open brace
31 }close braces end code blocks and must match an earlier open brace
|
Download/View SampleTextFileWriter.java