0

There's many projects which are using File.separator as path separators. But why do it's using on Android? I know that it can be useful on cross-platform apps, where Windows using \, and Linux using / as a separators, but are developers really think that Android projects will be launch on Windows in future, or is it only an historical reasons? Obviously, that it's more useful to use / instead of File.separator, even to add it to the variable like fileSep or fs.

Thanks!

Acuna
  • 1,741
  • 17
  • 20
  • Possible duplicate of [How do we get the file separators used by the different file systems?](https://stackoverflow.com/questions/9573297/how-do-we-get-the-file-separators-used-by-the-different-file-systems) – Tim Biegeleisen Jun 15 '17 at 04:54
  • From what I can see, there _might_ be a reason why even on Android the file separator might be different in different places. But for another reason, consider that you might write some generic code which your Android project uses, but which you could import into another Java project later on. – Tim Biegeleisen Jun 15 '17 at 04:55
  • Hm... Have you remember this places? I can't coming up with situations, when separators differ in one system. – Acuna Jun 15 '17 at 08:04
  • P. S. I don't think it's an dublicate, because at that answer was recommended to use `File.separators` to prevent the situations when separators are differ, but `File.separators` get only Linux-based format separators, which isn't differ within Linux-based systems. – Acuna Jun 15 '17 at 08:07
  • Look around at the comments, there is a reason to still take precautions. This might change in the future. – Tim Biegeleisen Jun 15 '17 at 08:10

1 Answers1

2

Android runs on top of Linux. So all file separators and similar settings use the same as Linux. People using File.separator are either running (or copying) Java code meant to be multi-platform, or are being extremely cautious.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • There is always the chance that a custom piece of code might be ported to another Java environment, e.g. J2EE. In this case, using the file separator would be a prudent move. – Tim Biegeleisen Jun 15 '17 at 08:05
  • 1
    @TimBiegeleisen true. I wouldn't go and change working code that uses it, or day sometime was wrong for using it. But I wouldn't rush to change code that wasn't either – Gabe Sechan Jun 15 '17 at 14:17