home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 1.7 KB | 67 lines |
- import java.io.*;
-
- /*
- * More.class similar to UNIX more utility
- */
- class More {
-
- public static void main (String args[])
- {
- String buf;
- FileInputStream fs=null;
- int nlines;
-
- if (args.length != 1) {
- System.out.println ("usage: java More <file>");
- System.exit (1);
- }
-
- /*
- * Try to open the filename specified by args[0]
- */
- try {
- fs = new FileInputStream (args[0]);
- } catch (Exception e) {
- System.out.println (e);
- System.exit (1);
- }
-
- /*
- * Create a BufferedReader associated with FileInputStream fs
- *
- */
- BufferedReader ds = new BufferedReader(new InputStreamReader(fs));
- BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
-
-
- nlines = 0;
- while (true) {
- try {
- buf = ds.readLine (); // read 1 line
- if (buf == null) break;
- } catch (IOException e) {
- System.out.println (e);
- break;
- }
- System.out.println (buf);
- nlines += 1;
- if (nlines % 23 == 0) { // 23 lines/pages vt100
- System.out.print ("-More-");
- System.out.flush ();
- try {
- keyboard.readLine ();
- } catch (IOException e) {
- }
- }
- }
- /*
- * close can throw an exception also,
- * and catch it for completeness
- */
- try {
- fs.close ();
- } catch (IOException e) {
- System.out.println (e);
- }
- }
- }