This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Having problem with Scanner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Having problem with Scanner" Watch "Having problem with Scanner" New topic
Author

Having problem with Scanner

Programmer Paul
Greenhorn

Joined: Aug 02, 2005
Posts: 1
Hi all, I am experencing some strange problems with the new Scanner class. I am running Java 1.5, update 4 on Windows XP. I have the code below, done using JCreator Pro:



The program works fine, but if I attempt to redirect input from a file, such as:

java test < commands.txt

it will crash with a NoSuchElementException.

Any idea what I am doing wrong?
Joe Sondow
Ranch Hand

Joined: Apr 10, 2005
Posts: 195
The problem has to do with your attempt to open an input stream using System.in, followed by another attempt to open an input stream using System.in without having closed the first stream. Here's a version of your program that doesn't have that problem:



SCJA 1.0 (98%), SCJP 1.4 (98%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having problem with Scanner
 
Similar Threads
input from console
Loop through the list of objects to get attribute.
Help needed with Scanner
What is wrong in this code ?
Question about restart