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

Discussion in 'Java' started by Vasu, Oct 18, 2008.

  1. Vasu

    Vasu Guest

    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
    Vasu, Oct 18, 2008
    #1
    1. Advertising

  2. 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


    You could try closing the stream.

    --

    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
    Knute Johnson, Oct 18, 2008
    #2
    1. Advertising

  3. 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
    Knute Johnson, Oct 18, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    448
    Luc The Perverse
    Oct 27, 2006
  2. Chris Thomasson
    Replies:
    10
    Views:
    546
    Alf P. Steinbach
    Nov 17, 2006
  3. helzer
    Replies:
    1
    Views:
    103
    Philip Hallstrom
    Oct 25, 2006
  4. Yusuf Celik

    It doesn't produce any output!

    Yusuf Celik, May 2, 2007, in forum: Ruby
    Replies:
    4
    Views:
    90
    Chris Carter
    May 3, 2007
  5. Kedar Mhaswade
    Replies:
    10
    Views:
    283
    Kedar Mhaswade
    Dec 27, 2010
Loading...

Share This Page