Swift 写入MacOS上的/etc/hosts
我想在MacOS上更改我的Swift 写入MacOS上的/etc/hosts,swift,macos,permissions,hosts,Swift,Macos,Permissions,Hosts,我想在MacOS上更改我的/etc/hosts文件 let url = URL(fileURLWithPath: "/etc/hosts"); newContentString.write(to: url, atomically: true, encoding: String.Encoding.utf8); 我得到了这个错误,这并非完全出乎意料;) 我可以阅读该文件,只想知道如何将字符串保存到/etc/hosts文件 马科斯 沙箱关闭了 迅捷 使用“/Users/myna
/etc/hosts
文件
let url = URL(fileURLWithPath: "/etc/hosts");
newContentString.write(to: url, atomically: true, encoding: String.Encoding.utf8);
我得到了这个错误,这并非完全出乎意料;)
我可以阅读该文件,只想知道如何将字符串保存到/etc/hosts
文件
- 马科斯
- 沙箱关闭了
- 迅捷
- 使用“/Users/myname/Desktop/hosts”时有效
Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “hosts” in the folder “etc”." UserInfo={NSFilePath=/etc/hosts, NSUserStringVariant=Folder, NSUnderlyingError=0x60000112c630 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}