• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Main args given as input to a File

 
vamsi acharya
Ranch Hand
Posts: 55
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys , am having some trouble with the following code snippet



I don't understand this code , the File should be given its path why is it so that it is given arguments of main method as input ? And also i am currently using NetBeans IDE, how to pass arguments of main method ?? Thanks in advance !
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vamsi acharya wrote:File should be given its path why is it so that it is given arguments of main method as input ?

You pretty much answered your own question. The arguments passed to main are the paths to the files!

Also, you should always indent your code for readability.
 
vamsi acharya
Ranch Hand
Posts: 55
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
vamsi acharya wrote:File should be given its path why is it so that it is given arguments of main method as input ?

You pretty much answered your own question. The arguments passed to main are the paths to the files!

Also, you should always indent your code for readability.


Thanks mate but how to enter the main arguments in an IDE ??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't use eclipse, sorry.
 
vamsi acharya
Ranch Hand
Posts: 55
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I don't use eclipse, sorry.


No problem hope anyone else can answer me that , can you please illustrate me how to enter path in main arguments in traditional way ??
 
Henry Wong
author
Marshal
Pie
Posts: 21016
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vamsi acharya wrote:
No problem hope anyone else can answer me that , can you please illustrate me how to enter path in main arguments in conventional way ??


It slightly different, depending on the version you are using, so take these instructions with a grain of salt.

Instead of just choosing the "run as" --> "application" option, choose "run configurations...". With some versions of eclipse, it may be named something slightly different. This should open a popup. Look for an "arguments" tab -- this should allow you to enter the command line arguments to give to the application.

[EDIT: it looks like from your first post, that you are using NetBeans, and not eclipse -- sorry, I don't use NetBeans]

Henry
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, yeah, I don't use netbeans either.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vamsi acharya wrote:
No problem hope anyone else can answer me that , can you please illustrate me how to enter path in main arguments in conventional way ??

By "conventional" I take it you mean the command line. For that you need to run your application like java MyApp /path/to/file
 
vamsi acharya
Ranch Hand
Posts: 55
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
vamsi acharya wrote:
No problem hope anyone else can answer me that , can you please illustrate me how to enter path in main arguments in conventional way ??

By "conventional" I take it you mean the command line. For that you need to run your application like java MyApp /path/to/file


Now i get it , thanks mate !!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic