SampleTextFileReader

From JavaWIDE

Revision as of 14:56, 23 April 2010 by Sonal (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

01 //start auto-imports
02 //end auto-imports
03 import java.util.*;
04 import java.io.*;
05 import java.net.*;
06 /**
07  * A simple application to read text from a file on the wiki.
08  @author Jam Jenkins
09  */
10 
11 public class SampleTextFileReader
12 {
13   public static void mainString[] args )
14   {
15   
16   
17     try //the following code may cause an exception if the file does not exist
18     {
19     
20       //open the input stream using the file name
21       File file = new File"Sample101.txt" );
22       Scanner scanner = new Scannerfile );
23       //read a line at a time
24       scanner.useDelimiter"\n" );
25       //read until there are no lines left and
26       //print the results to the console
27       
28       while scanner.hasNext() )
29         System.out.printlnscanner.next() );
30     }
31     
32     catch IOException e )                               //in case the file does not exist, say so
33     {
34       e.printStackTraceSystem.err );
35     }
36   }
37 }


Download/View SampleTextFileReader.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter