All pastes #979080 Raw Edit

stuff

public text v1 · immutable
·published 2008-04-10 01:40 UTC
rendered paste body
import java.lang.*;
import java.io.*;

public class FindString {
    /**
     * This program opens a file and searches the string from the file.
     *
     * @author        Ryan Modica
     */
    
    public static void main( String[] args ) {
        
        // checks to see if the args has more than two inputs
        if( args.length > 2 ) {
            System.out.println();
            System.out.println( "      Input error, more than two inputs" );
            System.out.println( "      Usage: java FindString " + 
                                "<search-string> <file-name>" );
            System.out.println();
        }
        // checks to see if the args has one input
        else if ( args.length < 2 ) {
            System.out.println();
            System.out.println( "      Input error, insufficient inputs" );
            System.out.println( "      Usage: java FindString " +
                                "<search-string> <file-name>" );
            System.out.println();
        }
        // the correct amount of inputs 
        else {
            // ensuring to see the filename's name is correct
            // finding the right string among the input and the file
            try{
                BufferedReader in;
                in = new BufferedReader( new FileReader( args[1] ) );
                String input = args[0];
                String string = in.readLine();
                int i = 0;
                int done = 0;
                
                while( i < string.length() - 1 && done == 0 ) {
                    int last = string.indexOf( " " );
                    String word = string.substring( i, last );
                    if( string.substring(i, last - 1 ).equalsIgnoreCase( input ) ){
                        System.out.println( in );
                        in.close();
                    }
                    i = i + last;
                }
            }
            catch( IOException e ) {
                System.out.println();
                System.err.println( "ExceptionType occurred: " + e );
                System.out.println();
            }            
        }
    }
} // FindString