/    Sign up×
Community /Pin to ProfileBookmark

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.

to post a comment
Java

6 Comments(s)

Copy linkTweet thisAlerts:
@CardboardHammerAug 08.2004 — 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.)
Copy linkTweet thisAlerts:
@sanjb1authorAug 16.2004 — 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.
Copy linkTweet thisAlerts:
@CardboardHammerAug 17.2004 — 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
Copy linkTweet thisAlerts:
@sanjb1authorAug 17.2004 — 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.
Copy linkTweet thisAlerts:
@CardboardHammerAug 18.2004 — 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.
Copy linkTweet thisAlerts:
@Khalid_AliSep 10.2004 — 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.
×

Success!

Help @sanjb1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...