Jai Gates wrote:
I need to read in multiple files from the command line.
You mean file names, right?
My idea on how to do this is simply to String ar = new String[args.length];
Then just loop through for (int i = 0; i < ar.length; i++)
File file = new File(args[i]);
//procedure on file;
Is this correct methodology?
If you mean, "Will it work?" then the answer is, "Try it and see!" You can put in something real yet simple for the "// procedure" comment, such as printing out the File's canonical path, or the results of a test for whether it exists.
If you mean, "Is the overall approach reasonable (ignoring any niggling syntax issues)?" then the answer is yes. One thing you could do so tidy up the code a bit is to use a foreach loop:
I missed the superfluous "ar" array. Add my voice to those of the others telling you to get rid of it.
Yes, you could do that. But creating an empty array with the same length as another array, just for the purpose of finding the length of that other array, is pointless. And other programmers looking at the code would be distracted, wondering why you did it. So you shouldn't do that.
Jai Gates wrote:Along those lines, (or perhaps I should post a new thread)
When a file is past via command line it is a String..
When we do a
Will that file be found and fed in even if in another part of the directory than the Projects?
The projects don't matter. If it's an absolute path, it will be found regardless, assuming it's a valid path. If it's a relative path, then what matters is the runtime's notion of current working directory. If you're running from within an IDE (not a good idea for a beginner), then the IDE may default it to something like your home directory or the directory where the IDE is installed, but you should be able to configure it in the Run settings for the project. If you do it on the command line (preferred approach), the working directory will be whatever directory you're sitting in when you launch the JVM.
Joined: Jul 11, 2012
So at command line it would look something like??: