How do you scan a file with java that isn't in the directory the java file is in?
For example: The java file is located at "C:\Files\JavaFiles\test.java" However, the file I want to scan is located at "C:\Data\DataPacket99\data.txt"
Note: I've already tried putting another java file in the "C:\Data" directory and using the test.java file as a class, but it doesn't work. It still tries to scan from the "C:\Files\JavaFiles" Directory.
You should be using an absolute path instead of a relative path.
You could use
File file = new File("C:/Data/DataPacket99/data.txt");
but it might make your life easier in the future to use a file chooser dialog if at any point the user will have to enter a file path.By using an absolute path instead of a relative.
Then you can write code that accesses that file object, using a InputStream or similar.
I would try this:
You need to use absolute paths in java.io stuff. Thus not
new File("data.txt")
, butnew File("C:/Data/DataPacket99/data.txt")
. Otherwise it will be relative to the current working directory which may not per-se be the same in all environments or the one you'd expect.