How do you allow a Java program to accept an arbitrary number of text files as input when the program begins?
I write a Java program, but I’m not sure how to introduce an arbitrary number of text files as input to the command line when running the program – i. e. When the Java program lista1 command. txt Text2. txt text 3. txt. . . Does anyone know how I could implement this, where there is an input variable number of user files? Thanks in advance.
Artikel How do you allow a Java program to accept an arbitrary number of text files as input when the program begins? yang terkait di situs lainnya:
How do you allow a Java program to accept an arbitrary number of ...
How do you allow a Java program to accept an arbitrary number of text files as input when the program begins? Filed under Programming 2 comments
Sumber: http://technicalcontents.com/programming/how-do-you-allow-a-java-program-to-accept-an-arbitrary-number-of-text-files-as-input-when-the-program-begins/35445/
How do you allow a Java program to accept an arbitrary number of ...
How do you allow a Java program to accept an arbitrary number of text files as input when the program begins?
Sumber: http://answers.yahoo.com/question/index?qid=20090912184209AA5Yguf
The Program // Explore
How do you allow a Java program to accept an arbitrary number of text files as input when the program begins? I write a Java program, but I’m not sure how to ...
Sumber: http://www.blogcatalog.com/explore/the+program/
Mehran Sahami Inspirational Speech
←How do you allow a Java program to accept an arbitrary number of text files as input when the program begins?
Sumber: http://technicalcontents.com/computer-science/mehran-sahami-inspirational-speech/35446/
How to Choose the Right Ribbon Blenders ?
How do you allow a Java program to accept an arbitrary number of text files as input when the program begins? →
Sumber: http://technicalcontents.com/programming/how-to-choose-the-right-ribbon-blenders/35444/
Comments
2 Responses to “How do you allow a Java program to accept an arbitrary number of text files as input when the program begins?”
Speak Your Mind
Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
notice every “main” class has a main function with a String-array argument, which contains all the arguments passed at the command-line. So, you could read each argument and load the corresponding text file:
public static void main(String[] args) {
for(String filename : args) {
//load or do whatever with the file; the filename is in “filename”
}
}
//pk
//detail explanation of reply given by user: _anonymous_
import java.io.FileInputStream;
public class Test6 {
public static void main (String[] args) {
for (String filename : args) {
try {
FileInputStream in = new FileInputStream (filename);
byte data[] = new byte [in.available()];
in.read (data);
in.close();
System.out.println (“File contents: n” + new String(data));
}
catch (Exception e) {
System.out.println (“Error in processing file: “+filename);
}
}
}
}