All pastes #928798 Raw Edit

Something

public text v1 · immutable
·published 2008-03-05 09:14 UTC
rendered paste body
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;

public class FileRewinder {

	public static void main(String[] args) {
		File inputFile = null;
		Scanner inputScanner = null;
		ArrayList<String> words = new ArrayList<String>();
		String Filename = "40caluserlist.txt";
		String FileOut = "output.txt";
		File outputFile = new File(FileOut);
		
		int lines = 0;
		
		

		
		try{
		inputFile = new File(Filename); //
		}
		catch(Exception e){
			System.out.println("Error:  " + e.getMessage());
		}
		
		try{
		inputScanner = new Scanner( inputFile );
		}
		
		catch(Exception e){
			System.out.println("Error:  " + e.getMessage());
		}
		
		
		
		//--------------READER-----------------------
		while ( inputScanner.hasNextLine() ) {
			words.add(inputScanner.nextLine());
			lines++;
		}
		
		inputScanner.close(); 	

		System.out.println("Lines: " + lines + "\n");
		System.out.println("Array Content: " + words + "\n");
		
		
		
		//--------------OUTPUT-------------------------
		PrintWriter outWriter = null;
		try {
			outWriter = new PrintWriter( outputFile );
		} catch ( FileNotFoundException e ) {
			
			//note the methods called on the File object below:
			System.out.println("Error:  cannot open "
			  + outputFile.getAbsolutePath() + " for writing.");

			
			outWriter.close(); 
			return; //end program
		}
		
		System.out.println("Array Size: " + words.size() + "\n");
		System.out.println("_____________________________OUTPUT______________________________\n");
		for ( int i = words.size() - 1; i > 0 ; i-- ) {
			System.out.println(words.get(i));
			outWriter.println(words.get(i));
			//outWriter.println( i + "," + i*i );
		}
		outWriter.println(words.get(0));
		
		outWriter.close();
		
		
		
		
	}

}