/*
* Compile: javac TestBuffer.java
* Run: java TestBuffer < someFile
*/
import java.util.Scanner;
public class TestBuffer {
public static void main(String args[]) {
Scanner sc = new Scanner( System.in );
String s;
int count = 0;
while ( sc.hasNextLine() )
count ++;
System.out.println(" Number of lines: " + count );
}
}
// to read from a named file use
// Scanner sc = new Scanner( new File("datafile") );
If you run this program with standard input connected to the keyboard
then you need to know how to signal "end of file". This is done by
typing at the beginning of a line either ^D on unix or ^Z on Windows.
That is, hold down the Control key while typing D or Z as appropriate.
Exercise: Write a program which copies its input to output inserting a blank line after each line (double spacing).
Exercise: Write a program which copies its input to output but replacing multiple blank lines by a single blank line.