## sbt test: AccessDeniedException

Faxe
Erstie
Beiträge: 15
Registriert: 3. Jun 2012 13:07

### sbt test: AccessDeniedException

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

vkuhn
Neuling
Beiträge: 6
Registriert: 25. Okt 2015 17:20

### Re: sbt test: AccessDeniedException

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.