1

I have a application. My application must run in Linux and Windows. I must write in main gradle-file any command. These commands content slash ("/" or "\"). How can I get what slash ("/" or "\") use (in language groovy)?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Typing "gradle file object" into Google gave me [this](http://www.gradle.org/docs/current/userguide/working_with_files.html) as the first hit. Google is your friend. In Java (and therefore Groovy) a `File` is platform agnostic - the delimiters will be sorted out automatically. – Boris the Spider Mar 18 '14 at 08:40

3 Answers3

4

If you work with Java, you can freely use '/' as a file separator. java.io.File will handle it for you. See similar SO question.

Gradle's file('Some\slashy/path') is a shorthand for
new java.io.File("Some\slashy/path"), and so deals with slashes correctly too.

Community
  • 1
  • 1
Seagull
  • 13,484
  • 2
  • 33
  • 45
  • 2
    The `file` method does a lot more than that (e.g. it makes paths relative to the current project), but always using slashes is indeed the best solution. – Peter Niederwieser Mar 18 '14 at 14:10
0

You should use java.io.File.separator instead of hard-coding it.

lucke84
  • 4,516
  • 3
  • 37
  • 58
Shriram
  • 4,343
  • 8
  • 37
  • 64
0

Usually Windows process "/" correctly. Just try

rjhdby
  • 1,278
  • 13
  • 15