import java.io._ class EndOfInput(stream : String) extends Exception class CharStream(fileName : String) { val file = new BufferedReader(new FileReader(fileName)) var current : Char = ' ' var eof : Boolean = false def next = { if (eof) throw new EndOfInput("reading" + file) val c = file.read() eof = (c == -1) current = c.asInstanceOf[Char] } next } object Test { // test for using CharStream def main(args : Array[String]) = { val s = new CharStream(args(0)) while (!s.eof) { print(if (s.current==' ') '_' else s.current) s.next } } }