Vasu wrote:
> Hi Friends!
>
> I have got the following code for converting Fahreignheit to Celsius,
> which writes the output to a file called fout and then prints the
> output from that file. It is compiled without producing any error,
> and when I try to run it do not get any error also, but it doesn't
> write anything on the screen either. When we take the output directly
> from the code (without writing it on a file and reading from there)
> it
> works excellently, but when we take the first route the above is the
> scene. Can somebody help tell me where is the problem and what is
> the
> solution if I want to read the results from a file. Here is the code
> I'm using :
>
> // Print a Fahrenheit to Celsius table
>
> // Write the Fahrenheit to Celsius table in a file
>
> import java.io.*;
>
> class FahrToCelsius {
>
> public static void main (String args[]) {
>
> double fahr, celsius;
> double lower, upper, step;
>
> lower = 0.0; // lower limit of temperature table
> upper = 300.0; // upper limit of temperature table
> step = 20.0; // step size
>
> fahr = lower;
>
> try {
>
> FileOutputStream fout = new FileOutputStream("test.out");
>
> // now to the FileOutputStream into a PrintStream
>
> PrintStream myOutput = new PrintStream(fout);
>
> while (fahr <= upper) { // while loop begins here
> celsius = 5 * (fahr-32) / 9;
> myOutput.println((float)fahr+" "+(float)celsius);
>
> fahr = fahr + step;
> } // while loop ends here
>
> } //try ends here
>
> catch(IOException e){
> System.out.println("Error: "+e);
> System.exit(1);
>
> }
> } // main ends here
> } //FahrToCelsius ends here
>
> Thanks for your help and cooperation
> Vasu
Kindly disregard my previous post.
To print to the screen, change fout to System.out in the PrintStream
constructor.
PrintStream myOutput = new PrintStream(System.out);
--
Knute Johnson
email s/nospam/knute2008/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
|