Reputation: 33
I tried using File, StreamWriter and StreamReader with a path outside of my project folder but it didn't work. It became projectPath\externalPath. For example my project path is F:\Project\ and my txt file is in D:\File.txt, Unity automatically read my path as "F:\Project\D:\File.txt", or it gives an error message: UnauthorizedAccessException
I tried using WWW too, but I got an error message "cannot convert WWW to string"
please help
Upvotes: 1
Views: 2180
Reputation: 33
After looking into various forums, I finally found my answer. Turns out you have to use an absolute path (like RSF said in the comments below) and uncheck the "read only" checkbox in the folder properties to avoid unauthorized access exception when you want to write into the file
Upvotes: 0
Reputation: 598
Try giving an absolute path instead of a relative path. e.g
var fullPath = "D:\<file-name>.txt";
var content = "testing";
File.WriteAllText(fullPath, content );
Above should write the file in your "D:" drive.
Upvotes: 3