Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Having a problem with java IO

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having a problem with java IO

    hey, im particularly new to this and i think this might be an easy one for you guys.
    It would be greatly appreciated if you could solve any one of this, or give me any help or insight into how i should go about solving this.

    it first asks the user to enter an integer, then you can either enter a new integer, open an existing file, allow current data to be altered, save data with same file name, or save data with new file name.

    please help!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Having a problem with java IO

    Would you like to cheat and have someone write the code for you? Or would you like to actually learn and write the code yourself?

    If the second option then what you need to do is make an attempt, start writing code and when you get stuck post your code, include error messages and ask a specific question. Do that and you will get plenty of help.

    On the other hand if you want the first option then all you will get is scorn and ridicule.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Having a problem with java IO

    Ok so im trying to open a new file, so far i have this
    public void newFile ()
    {
    title ();
    c.println (" Welcome, Come create a New File ");
    c.println ("");

    c.print ("Enter name for file : ");
    fileName = c.readLine ();

    try
    {
    output = new PrintWriter (new FileWriter (fileName));
    c.println ("");
    c.println ("You have just created the file " + fileName);
    c.println ("");

    askData ();

    output.close ();
    }
    catch (IOException e)
    {
    }
    }
    which first creates the file with an integer inside of it.
    then to open the actual file i just created i have this method :
    public void openFile ()
    {
    title();
    c.println ("which file");
    fileName = c.readLine ();

    try
    {
    // Open the file that is the first
    // command line parameter
    FileInputStream fstream = new FileInputStream (fileName);
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream (fstream);
    BufferedReader br = new BufferedReader (new InputStreamReader (in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine ()) != null)
    {
    // Print the content on the console
    System.out.println (strLine);
    }
    //Close the input stream
    in.close ();
    }
    catch (Exception e)
    { //Catch exception if any
    System.err.println ("Error: " + e.getMessage ());
    }
    }

    but the problem is that it opens the file in a really wierdish console called standard input/output console and is soon as i close it the whole program closes and i cant have that because i actually have other methods to run, so what do i do?

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Having a problem with java IO

    1. Wrap the code in code tags.
    2. Can you be more clear and explainatory in your askings? I don't know what do you mean by,
    and is soon as i close it the whole program closes and i cant have that because i actually have other methods to run, so what do i do?

Similar Threads

  1. Easy Java Problem
    By AATroop in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 12th, 2011, 02:05 PM
  2. Java Chat Problem
    By skillwill2002 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 4th, 2010, 10:30 AM
  3. please could you help me with this java problem im very lost
    By eyeore in forum Java Theory & Questions
    Replies: 4
    Last Post: September 7th, 2009, 09:19 AM
  4. java problem
    By Mj Shine in forum Java Theory & Questions
    Replies: 1
    Last Post: August 14th, 2009, 12:24 AM
  5. Java session problem
    By Padmaja in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: August 5th, 2009, 09:06 PM