This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

command line arguments for a file

 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have an file to read and i have given the file name inside the FileInputStream and i want to give the file name during run time like this

compile
javac FileRead.java
run
java FileRead 1.txt and the contents inside the file should be displayed

the coding is

what are all the necessary changes to be made for giving the input text file name during run time?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create a prompt to request a file name. You can use a file chooser. Lots of ways to do it.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code on line 12 is not doing what the comment on lines 10 and 11 say.

The args array that is passed to the main method (line 4) contains the command line parameters.
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya.. but how to use those arguments in the coding instead of giving the file name instead?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line this?
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm getting an error like this for the code what i'm using
error


can you tell why i'm getting this error?
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any one make my code reor free and get the output in the file? or can you send an error free code for java?please any one help me
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deepika deepi wrote:can any one make my code reor free and get the output in the file? or can you send an error free code for java?
No. That’s not how we work.
deepika deepi wrote:please any one help me
We are trying to help you. You asked how to get the file name from the command line and I sent you a link. Did you read it? You didn’t tell us what error you are suffering.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ShowSomeEffort.

Did you click the link that Campbell posted? The tutorial shows very clearly how to use the command line arguments.

Look at line 14 of your code. You're not using the command line arguments here.

The command line arguments are what is passed to the main method in the args array.

So, what do you think you need to change in line 14 so that the program is going to use the first command line argument there?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic