Search code examples
javaalgorithmbinary-searchpiping

Where do files have to be located to use algorithms on them (i.e. Binary Search)?


This has to be easy to solve, but I cannot seem to get it right.

My command: java BinarySearch tinyW.txt < tinyT.txt

throws: "The system cannot find the file specified"

My environmental variable classpath is pointing to the directory containing these files, so I assume that is not where the system is looking.

Where is the system looking for these files i.e. where should I put them?

Thanks for taking the time!!


Solution

  • Java programs read files like any other program: from the file system. If you execute a program from the directory /foo/bar and ask the program to read the file bla.txt, the program will read the file /foo/bar/bla.txt.

    That has nothing to do with the classpath. The classpath tells the JVM where classes constituting the program to start are located. In this case, where the JVM can find the BinarySearch class and all the classes it uses, recursively.