0

How can i get this File myTempDir = Files.createTempDir(Path path, String prefix, FileAttribute) to work in windows.

I'm using java 7. On linux I can pass a PosixFilePermissions.asFileAttributes for the 3rd parameter.

What is the equivalent fileAttributes for windows.

I think this method always expects a fileAttribute object. Is there an empty fileAttribute that i can pass in?

hba
  • 7,406
  • 10
  • 63
  • 105

1 Answers1

5

If you took a look at the API for
Files.createTempDirectory(Path, String, FileAttribute<?>...), you would actually see that the FileAttribute<?>... parameter is optional:

attrs - an optional list of file attributes to set atomically when creating the directory

And since the method is implemented using varargs, it is perfectly valid to omit the parameter entirely:

Files.createTempDirectory(Paths.get("."), "foo");
Jeffrey
  • 44,417
  • 8
  • 90
  • 141
  • [Relevant answer w.r.t. varargs](http://stackoverflow.com/questions/12534531/how-to-pass-elements-of-an-arraylist-to-variadic-function/12534579#12534579). In any case, this is the "empty file attributes" that OP is looking for, so +1. – Brian Aug 15 '13 at 19:33
  • There doesn't seem to be a version of Files.createDirectory() that allows you to omit the attributes. – LegendLength Jun 29 '17 at 11:33