java file i/o program

Discussion in 'OT Technology' started by quasar, Sep 21, 2004.

  1. quasar

    quasar New Member

    Joined:
    Jun 18, 2003
    Messages:
    965
    Likes Received:
    0
    Location:
    Sun Diego
    Could someone please help me with my java program?

    public static void connect2InputFile()
    {
    BufferedReader inputStream = new BufferedReader(new FileReader(input));
    }

    public static void connect2OutputFile()
    {
    PrintWriter outputStream = new PrintWriter(new FileOutputStream(output));
    }

    I don't know how to get these methods to pass the stream name back to the main program.
     
    Last edited: Sep 21, 2004
  2. WERUreo

    WERUreo Imua!

    Joined:
    Oct 15, 2003
    Messages:
    566
    Likes Received:
    0
    Location:
    Daytona Beach, Florida
    What exactly did you need help with, reading it?? Posting code and asking for help does no good unless you specify what kind of help you need...
     
  3. quasar

    quasar New Member

    Joined:
    Jun 18, 2003
    Messages:
    965
    Likes Received:
    0
    Location:
    Sun Diego
    java gurus please help
     
  4. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    Code:
    public static void main(String[] args)
    {
         BufferedReader stream = connect2InputFile();
    }
    
    public static BufferedReader connect2InputFile()
    {
         BufferedReader inputStream = new BufferedReader(new FileReader(input));
         return inputStream;
    }
    
    Change the void return value to BufferedReader/Writer and assign it to a variable in the main method. You'll also need try-catch blocks to do IO.
     
  5. quasar

    quasar New Member

    Joined:
    Jun 18, 2003
    Messages:
    965
    Likes Received:
    0
    Location:
    Sun Diego
    thank you! :bowdown:
     
  6. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    not to be an ass, but next time you post code use the code tags.

    and Nocera you beat me to it.
     

Share This Page