Can somebody please help me with this code? I have the program correctly coded and operating properly, however, I forget how to write my output to a text file. Can somebody please help me here? Thanks.
If you have got a Scanner, you can use its opposite, which is called Formatter, and use its format method.
You need to find out about the % tags first; there are some simple examples in the Java Tutorials and fuller details in the API for Formatter.
Joined: Oct 13, 2005
I see you have got the % tags working: that's half the problem solved, and Fred's suggestion looks really nice.
Joined: Jan 13, 2009
ok. How would I use that in my program. I don't really understand what "java HeatIndex > filename.txt " means.
to run your program, you probably type something like this:
Your program writes everything to what's called 'Standard out', which usually means the console. Most operating systems let you 'redirect' standard out to some other 'thing' - a printer, a file, a port maybe...
to do that, you tell the OS "hey, when you run this program, redirect the standard out to this other place". That's what the '>' does. Think of it like an arrow, pointing to where you want your output to go. If you want it to go to a file called "output.txt", you'd write
java HeatIndex > output.txt
Note that you can put a full path here:
java HeatIndex > C:\logs\heatindex\outout.txt
Each time you do this, any existing file with that name will be blown away, and ONLY the output from the new run will be saved there. If you want to APPEND your new data to the end of the file (or create it if it doesn't exist), you can do this: