How to make sure that your files will be read on both linux/windows
I'm currently using this to read my files as inputStream, it works under windows, will 开发者_开发知识库this work in LINUX?
File file = new File(currentDirectory.getCanonicalPath().toString() + "\\" + "myfile.txt");
If not what is the right way to read files, this "\\
" looks kind of "fishy"
ADD-ON
I forgot this :
File currentDirectory = new File(".");
Instead of hard-coding the filename separator, use File.separator
there.
Better yet, use:
File file = new File(currentDirectory, "myfile.txt");
actually "/" works on Windows too.
精彩评论