Issue
I am trying to compile and run this program by using eclipse. How do I do this? I cant include the command line in the program. how do i use eclipse to run the program by using this command line?? I know theres another way of making the program by using Scanner but how do i run this one properly??? Cant post an image. Just joined.
INPUTTING FROM A FILE
Display a text file.
/*To use this program, specify the name
of the file that you want to see.
For example, to see a file called TEST.TXT,
use the following command line.
java ShowFile TEST.TXT */
import java.io.*;
class ShowFile {
public static void main(String args[])
throws IOException
{
int i;
FileInputStream fin;
try {
fin = new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;
} catch(ArrayIndexOutOfBoundsException exc) {
System.out.println("Usage: ShowFile File");
return;
}
// read bytes until EOF is encountered
do {
i = fin.read();
if(i != -1) System.out.print((char) i);
} while(i != -1);
fin.close();
}
}
Solution
Right click on your program, Hover over to Run As and Click Run Configurations You will see a dialog box, now click on Arguments tab and specify the command line arguments.
Answered By - Shailendra Patel