www.webdeveloper.com
Results 1 to 7 of 7

Thread: Java Netbeans 3.5.1

  1. #1
    Join Date
    Aug 2004
    Location
    London
    Posts
    3

    Java Netbeans 3.5.1

    Hi all,
    Just wondering if you could help me out a bit with netBeans (the help file is no good at this).
    What i want to do is just write a simple java program that takes input. Now i know how to pass arguments on their own (Build > Set Arguments) which works as if the user was typing the arguments at the command prompt, but i need to be able to do the same but the program should read from a file. Basically when you use the command prompt you would type 'java javaFile fileToPass.txt' to make the javaFile read input from fileToPass.txt (obviously its been compiled first).
    However, i have got some problems at command prompt and would prefer to just use netBeans to read from a file.
    Does anyone know how i can do this in netBeans.
    Thank you.
    SanjB.

  2. #2
    Join Date
    Nov 2003
    Posts
    655
    I don't do netBeans, but perhaps I can ask a question to help clarify for others what the exact thing you need help with...

    Is the question basically, "How do I read a file using netBeans?"

    Or do you actually know how to read a file, but you're looking for a way to use it as a substitute for command line arguments? (In which case, I'd suggest using XML for the file and storing the info in the form of parameter name + parameter value. Then parse out the parameters and associated values, if any, and take the appropriate action.)

  3. #3
    Join Date
    Aug 2004
    Location
    London
    Posts
    3
    Hi,

    The answer to this is your sentence as follows:

    'Or do you actually know how to read a file, but you're looking for a way to use it as a substitute for command line arguments? '

    However, i am not that experienced as a programmer and therefore have basically no idea what this means :

    'I'd suggest using XML for the file and storing the info in the form of parameter name + parameter value. Then parse out the parameters and associated values, if any, and take the appropriate action'

    Thank you.

  4. #4
    Join Date
    Nov 2003
    Posts
    655
    OK, so you know how to open and read files.

    What I'm suggesting is that you use XML for the formatting of the file you read the parameters from.

    You could read in values from the XML file sequentially, which would correspond to using commandline parameters that were used by their order: foo.exe 1 blah

    Or you could assign names and values to parameters, giving you much more flexibility and corresponding to a command line where parameters have a name specified first, followed by their value: foo.exe -count 1 -word blah

  5. #5
    Join Date
    Aug 2004
    Location
    London
    Posts
    3

    Red face

    Hi,
    Oops I am sorry, I think I read your sentence about :

    'Or do you actually know how to read a file, but you're looking for a way to use it as a substitute for command line arguments? '

    rather lightly. I dont actually know how to read a file (of inputs) that java should look in. I was thinking more along the lines of do i know how to open a java file in netBeans (like you would in Microsoft word or something), i know it sounds rather ignorant :-D

    Let me put it as simple as i can, when you run some java program that you have made that prompts you to input some value(s) what you would do at that point (when it prompts you) is to type it in. Instead of typing in the values manually i would like to put them in a file (for example if there are many values and i dont wish to type them in or paste them everytime). Then i can use the command

    java someJavaFile < someFileToRead

    i cant remember for sure whether its < or > but its to that effect.
    Then what java will do is to take (when it prompts) the inputs from that file (every line is like typing at a new prompt - i can set it up that way) as if it was an input from you physically typing it at the keyboard. I would just like to know how you can do this in netbeans or if it is at all possible to do it in netBeans since you can do it at the command prompt.
    Thank you and sorry for the trouble.

  6. #6
    Join Date
    Nov 2003
    Posts
    655
    For command line standard IO redirection:
    < is input
    > is output

    I know practically nothing about netBeans, so I can't really be of much help...

    I still am somewhat confused by exactly what you're looking for... Do you mean that for just one component (netBean), you want to be able to redirect standard input to come from a file? Just that component, and not the rest of the application it is used in?

    Hmmm... Maybe I get it now... is the netBean a GUI component, not using a console? In which case, I have no idea if you can redirect input. However, if nothing else, you should be able to slap together an ad hoc solution along the lines of what I proposed earlier.

  7. #7
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    name of the file that you are trying to pass is just another parameter...create a file object in the main method...suppose the input wil only have 1 parameter and that will be a file

    File file = new File(args[0]);

    and then you can use file object to read it thru....ofcourse you will have to write error handlings and such...but above is the basic logic sto start with.
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles