FileDocCategorySizeDatePackage
Grep.javaAPI DocExample1284Thu Aug 08 12:29:26 BST 1996None

Grep

public class Grep extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        if ((args.length == 0) || (args.length > 2)) {
            System.out.println("Usage: java Grep <substring> [<filename>]");
            System.exit(0);
        }
        
        try {
            DataInputStream d;
            if (args.length == 2) 
                d = new DataInputStream(new FileInputStream(args[1]));
            else
                d = new DataInputStream(System.in);
            
            GrepInputStream g = new GrepInputStream(d, args[0]);
            
            String line;
            for(;;) {
                line = g.readLine();
                if (line == null) break;
                System.out.println(line);
            }
            g.close();
        }
        catch (IOException e) { System.err.println(e); }