Forward slash or backslash?

Patriot524 picture Patriot524 · Nov 4, 2013 · Viewed 44.4k times · Source

I am looking to write and read text files to and from (respectively) a directory different from that of my program. When I specify a directory to write to or read from, should I be using forward slashes or backslashes to identify a file path?

Answer

Paul Draper picture Paul Draper · Nov 4, 2013

Using forward slashes will make it system independent. I'd stick to that for simplicity.

Consider using java.io.File.separator if you ever display the path to the user. You'd rather not surprise those Windows users. They're a jumpy lot.