©1994-2003 Kevin Boone
Home     Section index     K-Zone home Simple Java programs

Site search

Glossary
Confused by computer jargon? Look it up!

Shameless plug


Now available!

Articles
- Ten-minute guide to setting up a WAP site

- Talk like your boss: new developments in managerese

More...

Development
File handling in the Linux kernel

Java development for the Sony-Ericsson P800

SunONE Application Server 7 FAQ

More...

Linux
Using Linux with the Treo 600

- Linux on the Tecra M1

- Some notes on openzaurus

More...

Download
Java stuff

Linux stuff

More...

(Please read the download policy)

Home automation
The X10 system

Linux TW723 driver

More...

The K-Zone
K-Zone computing

K-Zone law

K-Zone education and science

K-Zone motorcycles

K-Zone DIY

K-Zone railways

K-Zone martial arts

About the author

K-Zone home page

 
Software development
Computing
Hello1.java
Add1.java
Add1_1.java
AwtTest.java
Button1.java
Button2.java
Calculator.java
CalculatorApp.java
ClockApplet.java
CountSpace1.java
DateTime.java
Div1.java
DoNothing.java
Factorial1.java
Factorial2.java
FontChooser.java
IfTest.java
Inheritance1.java
Loan.java
DiceThrower.java
MultiplicationTable.java
Queue.java
Reverse1.java
SoundApplet.java
Stressometer.java
WebMerge.java
Zener.java
`TextReaderTest' example program: demonstrates encapsulation of file handling classes

TextReader.java

/*
TextReaderTest

This program defines a class called 'TextReader' which is intended to
simplify reading text files a line at a time. The TextReader class
manages all the intermediate files that are needed for this operation,
so the class that uses it can read a text file without worry about these
details
*/

import java.io.*;

class TextReader 
{
BufferedReader br;

public TextReader(String filename) throws java.io.IOException, java.io.FileNotFoundException
	{
	File aFile =new File(filename);
	FileInputStream fis = new FileInputStream(aFile);
	InputStreamReader isr = new InputStreamReader (fis);
	br = new BufferedReader (isr);
	}

String readLine() throws java.io.FileNotFoundException, java.io.IOException
	{
	return br.readLine();
	}
}


/*
TextReaderTest
This class tests the TextReader by opening a file and reading the first line
from it
*/

class TextReaderTest 
	{
	public static void main (String args[])
		{
		try
			{
			TextReader textReader = new TextReader ("TextReaderTest.java");
			String s = textReader.readLine();
			System.out.println(s);
			}
		catch (Exception e)
			{
			System.out.println(e.toString());
			}
		}
	}