-1

when compiling a java program you normally use java programName. What does the below line mean?

java BinarySearch whitelist.txt < input.txt What are the 2 txt files doing (is it input output files) what is the < mean

Thanks

user41805
  • 523
  • 1
  • 9
  • 21
  • 1
    Don't you use `javac fileName` for compiling? – user41805 Oct 03 '15 at 18:49
  • sry for the confusion, what does whitelist.txt < input.txt mean in the below BinarySearch compilation java BinarySearch whitelist.txt < input.txt – user2892493 Oct 03 '15 at 18:50
  • 2
    `java JavaProgramName` used to run a program not compile. – ashiquzzaman33 Oct 03 '15 at 18:52
  • This has nothing to do with Java (or compilation, for that matter). It says you want to run a program `java` with two arguments, "BinarySearch" and "whitelist.txt", with the program's stdin coming from the contents of the file input.txt. This is all bash (or zsch) functionally, not Java. – yshavit Oct 03 '15 at 18:55
  • so the stdIn is coming from input.txt and then the output is written to whitelist.txt. is that correct? – user2892493 Oct 03 '15 at 18:58
  • See also http://stackoverflow.com/questions/15680530/bash-read-stdin-from-file-and-write-stdout-to-file – yshavit Oct 03 '15 at 18:59
  • No, the input is coming from input.txt, and there's no way to know how whitelist.txt is used. It all depends on what BinarySearch.main does with the first element of its String array – yshavit Oct 03 '15 at 19:00

2 Answers2

1

In this case, the < character will redirect the standard input to the input.txt file. This means that System.in will represent the file, rather than the console input. Using the > character would instead redirect the standard output to the file, so that System.out will represent the file, rather than the console output. These characters are not interpreted by the java virtual machine, but by the shell.

Since there is no special character in front of whitelist.txt, it just acts as an argument to the java program, and will be stored in args[0] (or whatever the arguments variable is named in the program).

By the way, using the java program command will not compile the java file, it will instead run the compiled class file. To compile a java file, use the javac file.java command.

SamTebbs33
  • 5,507
  • 3
  • 22
  • 44
0

The args* following **BinarySearch are inputs into the program.

As shown in the documentation for the code, < is being used for redirect from StdIn.

enter image description here

Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51