Advertisement
StormWingDelta

FileLoaderNotePad

May 28th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. import java.io.*; //necessary for File and IOException
  2. import java.util.*; //necessary for StringTokenizer and Scanner
  3. import java.text.*; //necessary for NumberFormat
  4. public class BaseClass
  5. {
  6.     public static void main( String args[] ) throws IOException
  7.     {
  8.         NumberFormat fmt = NumberFormat.getNumberInstance( );
  9.         fmt.setMinimumFractionDigits(3); //may need to change value
  10.         fmt.setMaximumFractionDigits(3); //may need to change value
  11.         Scanner sf = new Scanner(new File("C:\\Documents and Settings\\Roland.USER-6FEF0AE329\\My Documents\\JavaProgramsMade\\JavaLessons\\TextFiles\\FileName.in"));
  12.         int maxIndx = -1; //-1 so when we increment below, the first index is 0
  13.         String text[] = new String[1000]; //To be safe, declare more than we need
  14.         while(sf.hasNext( ))
  15.         {
  16.             maxIndx++;
  17.             text[maxIndx] = sf.nextLine( );
  18.             //System.out.println(text[maxIndx]); //Remove rem for testing
  19.         }
  20.         //maxIndx is now the highest index of text[]. Equals -1 if no text lines
  21.         sf.close( ); //We opened a file above, so close it when finished.
  22.         //System.exit(0); //Use this for testing... to temporarily end the program here
  23.         for (int j = 0; j <= maxIndx; j++)
  24.         {
  25.             //Typically, only one of the following two will be used.
  26.             //StringTokenizer st = new StringTokenizer( text[j] );
  27.             //Scanner sc = new Scanner(text[j]);
  28.             //...code specific to the task...
  29.             //System.out.println(text[j]); //Remove rem for testing
  30.            
  31.            
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement