"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Sep 17, 2006
Originally posted by Luigi Melanson: .... prompt for a file name instead of predefining "filein.txt" in the code Any help would be appreciated,
I Think I understand what you are wrestling with here. The cite Marc Weber provides is certianly something you need to keep on your list, but the problem is asking the user for a filename then reading that in.
I do not know how to read the standard input, but you have the option of having the user type the name of the file when they start the program: at the command line when they start the program. This is one way to do it:
This now has a File object that literally uses the name that was typed in. It is not opened or anything, look through http://java.sun.com/j2se/1.3/docs/guide/io/io-maj.html very carefully to get your bearings before trying to do anything with the file. The Scanner Marc mentioned will more than likely read() what the user types in, but you will have to read up on it to use it. To ask the user for a file name, you do this:I prefer my programs not to sit and wait on the user to type in something, it better be there when they invoke the program.
Either way, it looks to me what you are doing is struggling with what to do with the stuff the user types in, as a string problem rather than the problem you describe. I know it well, hung for a waste of time seemingly getting nothing done.
This is called "Re-inventing the wheel." in computer work.
[ December 24, 2006: Message edited by: Nicholas Jordan ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Joined: Oct 17, 2005
Use the scanner class to read in a string as a filename.
Make sure you catch the "FileNotFoundException"...
Stephen Foy - Microsoft Application Development Consultant