Results 1 to 6 of 6
  1. #1
    wiz0r is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default [SOLVED] File reading question

    Hello!

    Ok, so I got a project to do, and I really don't want to post my code, since well, yeah, its due date is this Monday, and many people of my class can access this site!

    So anyway, here's my question:

    I got an Object named "Variable" which stores the name of the variable, the data type (in this case can only be int or word, where word works almost like a String) and the value of the variable. While the program runs it stores several Variables in an ArrayList<Variable>. Now, when I exit the program, it writes in a .txt file the entire Variables name, type, and value.

    Now, what I'm asked to do in the project is to run the program from the command window. I can do that, BUT I also need to do the following:

    Run the program but if I give the following command:

    Java P24015.MyShell <filename>

    where P24015 is the name of the package and MyShell is the name of the Main class.

    The program runs, and stores the entire variable's name, type and value that are in that fileName.txt in the ArrayList<Variable> and I can continue running the program with all of those Variables already stored. What I need to do it is just a "standBy".

    I definitely have no idea how to do that. I need info on how to do it, or give me a link where it explains this. I can't find any info on this. Please, any help is greatly appreciated.

    Edwin
    Last edited by wiz0r; 04-19-2009 at 03:30 AM.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    What's a "standBy"? What you need to do is open and parse the contents of the given file.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    I think by standBy he means wait... If this is true, your best bet might be to check out Threads-notifyAll() and wait()...
    Who Cares... As Long As It Works...

  4. #4
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    to attempt to shed some light on what the OP is trying to say...

    when the program is started, there needs to be an option to enter a filename where saved data is stored? Sounds like a write/read XML file is needed, or a FileOutputStream/FileInputStream combined with an ObjectOutputStream/ObjectInputStream. Personally, I make my classes serializable and use input/output streams, as the code is just simpler. Because ArrayLists are already serializable, you can just write them to a file, and offer the user an option such as load? y/n. A FileOutput/InputStream takes a parameter of type File, so the user does not need to enter a filepath. Just ask if you would like an example, I'm sure I could find one somewhere.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  5. #5
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    As for "standby"... perhaps just allowing the program to exit and reload upon starting it is what is meant?
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  6. #6
    wiz0r is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default

    Ok, first of all, I'm sorry if I'm not being clear. All the instrucions are in spanish(my first language), so please bear with me.

    What's a "standBy"? What you need to do is open and parse the contents of the given file.

    By standBy, it is exactly as Singing Boyo said. The program must exit and reload upon starting it.

    when the program is started, there needs to be an option to enter a filename where saved data is stored? Sounds like a write/read XML file is needed, or a FileOutputStream/FileInputStream combined with an ObjectOutputStream/ObjectInputStream. Personally, I make my classes serializable and use input/output streams, as the code is just simpler. Because ArrayLists are already serializable, you can just write them to a file, and offer the user an option such as load? y/n. A FileOutput/InputStream takes a parameter of type File, so the user does not need to enter a filepath. Just ask if you would like an example, I'm sure I could find one somewhere.

    Mm, I'll post a screenshot of how the program runs(attachment 1), so you can see what my program does.

    There are many other commands, such as copy, duplicate, find, sort, and some others. Right now I'm trying to implente the standBy command. The standBy command must store the name, type, value of the variables in a text. Then if I want to run the program from the command window, and I give it a parameter such as file.txt the program can use the variables stored there and use them in the program.

    In the attachment 2 there is the output of the text given by standBy.
    Attached Thumbnails Attached Thumbnails [SOLVED] File reading question-test.jpg  
    Attached Files Attached Files

Similar Threads

  1. Reading from file
    By kiab3000 in forum New To Java
    Replies: 0
    Last Post: 03-14-2009, 06:33 PM
  2. help in reading file.
    By wanw84 in forum New To Java
    Replies: 2
    Last Post: 10-21-2008, 03:17 PM
  3. Reading a file
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-30-2007, 12:23 PM
  4. Reading a file for use
    By peachyco in forum New To Java
    Replies: 2
    Last Post: 11-27-2007, 03:49 AM
  5. Question abt.reading xml file using java
    By gvi in forum Advanced Java
    Replies: 6
    Last Post: 11-08-2007, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •