How create file in a protected dir? mac

Hi I was trying to do this:

File saveFile{File::getSpecialLocation(File::SpecialLocationType:: userApplicationDataDirectory).getChildFile("Opera Terza Gestionale/fileSaved.xml")};

And it doesn’t create anything, while this works:

File saveFile{File::getSpecialLocation(File::SpecialLocationType:: userDesktopDirectory).getChildFile("Opera Terza Gestionale/fileSaved.xml")};

How can I have access to protected directories on mac?

I think the parent directory must exist before trying to create the file itself. Perhaps you already had a file named Opera Terza Gestionale on your desktop before testing this code.

Your code works for me as long if I call saveFile.create() before saveFile.replaceWithText ("...").


Unrelated, but it’s probably a better idea to put your supporting files into ~/Library/Application Support rather than putting them directly in ~/Library.

1 Like