Text file extension?
Hello all, quick question, can i replace:
String question = "D:\\Chris Halfpenny - Java Assignment\\Program Part 3\\Question.txt";
I have tried an it comes up with file not found exception.
String question = "Question.txt";
Any ideas :D
Where is the file? Is it in the current directory?
One way to find the current directory is to open a file for output and see where it is written.
I'm sure there is a faster/easier way but I don't have it available right now.
No the program works fine with the first code i have shown, i just wanted to know if theres anyway to shorten the file extension to just "Question.txt" instead of the longer version, its just if i was to move the program to say another hard drive i would have to go back and change the file extension in the program, oh yeah and the question.txt file is in the root of the program.
It's often better to use a relative path vs the full path.
You didn't say if you wrote a test program to find where a file would be if you wrote it without any path.
Try that and see.
If the program and file might be moved independently, the thing to do would be to pass in the current location of the file to your program as a parameter when you run it.
Originally Posted by chrisLU5
Otherwise, if they're always in the same relative position but the drive letter changes, use a relative path as Norm suggested.