FileDocCategorySizeDatePackage
TestBufferedReader.javaAPI DocExample1599Thu Mar 14 12:39:46 GMT 2002testbufferedreader

TestBufferedReader

public class TestBufferedReader extends JFrame

Fields Summary
private File
inFile
private FileReader
fileReader
private BufferedReader
bufReader
private JTextArea
j
private Container
c
Constructors Summary
public TestBufferedReader()

	  
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				dispose();
				System.exit(0);
			}
		});
		// set up the container in which components can
		// be placed
		c = getContentPane();
		// add the only component, the JTextArea
		c.add(j);
	
Methods Summary
public static voidmain(java.lang.String[] args)

		System.out.println("Starting TestBufferedReader...");
		TestBufferedReader mainFrame = new TestBufferedReader();
		mainFrame.setSize(400, 400);
		mainFrame.setTitle("TestBufferedReader");
		mainFrame.setVisible(true);
		mainFrame.readFile();
	
public voidreadFile()

    	// Open the file
    	inFile     = new File("c:\\animals.dat");
    	// Create a file stream, wrapping the file
    	fileReader = new FileReader(inFile);
    	// Create a second wrapper,
    	bufReader  = new BufferedReader(fileReader);
    	// Read in the first line...
    	String s;
    	// Read in 7 lines (how can this be improved?)
    	for (int i=0; i<7; i++) {
    		s = bufReader.readLine();
			// Add the new string to the text area
          	j.append(s);
           	j.append("\n");  // Append a new line character to improve formatting
    	}