Reputation: 1782
I had hard coded path in my code. Now, I have to use File.separator (or any other class) so the my path will work on Windows or Linux machine.
Why my new code isn't working? Help me overcome the issue.
This is my old code (that works on Windows):
readFile("./Use-cases/"+duplicatedExcelText);
And this is my new code that causes exception and errors:
readFile(File.separator+"."+File.separator+ "Use-cases"+File.separator +
duplicatedExcelText);
Upvotes: 1
Views: 244
Reputation: 1782
This solved my problem:
readFile("."+ File.separatorChar + "Use-cases" +
File.separatorChar + duplicatedExcelText);
Upvotes: 1
Reputation: 140457
The problem is that you construct a string that goes:
'\' + "." ...
in the end.
Windows doesn't like that for relative paths!
And according to this, you can use /
for all OSes. Using File.separator is only recommended when you want to display the final path to human users (to avoid confusing them).
Upvotes: 0