Seite 1 von 1

sbt test: AccessDeniedException

Verfasst: 21. Nov 2016 21:25
von Faxe
Greetings!

I'm having issues with the FileSerializierTest as it fails due an AccessDeniedException. I use java.nio.file to write to a File, but I assume I somehow messed it up.

Before writing to a file a check if it exists and create a file otherwise. However, the creation fails due to the aforementiond Exception if repeatedly called (as done in the tests), therefore messing up the test.

Code: Alles auswählen

if(!Files.exists(path))
      Files.createFile(path)
Does anyone has a clue on how to fix this problem?

Best Regards

Re: sbt test: AccessDeniedException

Verfasst: 22. Nov 2016 16:30
von vkuhn
If you're trying to write into a non-existing directory, you'd first have to create it with

Code: Alles auswählen

Files.createDirectories(file.toAbsolutePath.getParent)
If that doesn't help, running as Admin seems to help some people (on Windows).
Unfortunately, that didn't help me either. For me

Code: Alles auswählen

Files.createFile(path)
din't work everytime, but

Code: Alles auswählen

path.toFile().createNewFile()
did work, though I'm not quite sure why that is.