13.07.2015 Views

I/O Fundamentals

I/O Fundamentals

I/O Fundamentals

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java Input and Outputboolean readingVariable = false;while(c != -1) { // loop until end-of-file// the current variable or operatorStringBuffer chunk = new StringBuffer();// are we done with the current chunk?boolean chunkEnded = false;while(!chunkEnded) {switch(c = pbr.read()) {// operator characterscase '+':case '-':case '*':case '/':case '=':// if we're working on an operator, append to itif (!readingVariable)chunk.append((char)c);// if we're working on a variable:// -- STOP building the variable// -- switch mode to "operator"// -- put back the operator char for laterelse {// Switch reading mode to operator for next timereadingVariable = false;// PUT IT BACK so we can read it next time!pbr.unread(c);chunkEnded = true;}break;// separator characters// if any of these chars are encountered, we// stop building the current variable or operatorcase '\n': // unix newlinecase '\r': // mac newline// dos newline is "\r\n"case '\t': // tabcase ' ': // spacecase -1: // end-of-filechunkEnded = true;// note that the loop expects readingVariable// to represent the _opposite_ of what the current// chunk is when printing itreadingVariable = !readingVariable;break;variable// any other character is considered part of adefault:// if we're working on a variable, append to itJava Input and Output -32© 1996-2003 jGuru.com. All Rights Reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!