Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 135992

Do we have to use system dependent file separator in java.io.File path?

Do we actually need to provide correct file separator in java.io.File path expression? In other words, does it make any difference to write path + File.separator + fileName instead of path + "/" + fileName for any OS?

Upvotes: 0

Views: 1310

Answers (3)

jagr
jagr

Reputation: 339

It's probably that you don't know in which version of Windows will be your application and for this reason I recommend you to use always System.getProperty(file.separator);

Upvotes: 1

Aleksander Gralak
Aleksander Gralak

Reputation: 1509

I usually stick to File.seperator .

However I noticed that Java is smart enough to handle correctly "/" on any operating system.

Upvotes: 0

sksamuel
sksamuel

Reputation: 16387

Some people might say technically yes, but in practice since windows works with either \ or /, just use unix file separators and you'll be fine.

Upvotes: 2

Related Questions