Code doesn't produce anything on screen - Doesn't give any erroreither while compiling / running.

V

Vasu

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
 
K

Knute Johnson

Vasu said:
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

You could try closing the stream.
 
K

Knute Johnson

Vasu said:
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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top