开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜