Hi,
I’m trying to read and edit the macOS hosts file into a TextArea.
Reading : works well slight_smile:
Dim t As TextInputStream
Dim f As FolderItem
Dim x as String
f = FolderItem.DriveAt(0).Child("private").Child("etc").Child("hosts")
if f<> nil then
t = TextInputStream.Open(f)
t.Encoding = Encodings.UTF8
While Not t.EndOfFile
x = t.ReadLine
TextArea1.Text = TextArea1.Text + EndOfLine + x
Wend
t.Close
else
//user cancelled
end
But, I have an error on writing the file :
Var f As FolderItem
Var t As TextOutputStream
f = FolderItem.DriveAt(0).Child("private").Child("etc").Child("hosts")
If f <> Nil Then
Try
t = TextOutputStream.Open(f). <-------- ERROR !
t.Write(TextArea1.Text)
t.Close
Catch e As IOException
// handle error
End Try
End If
Unfortunately not, because as Greg has already said, you still won’t have the correct write permissions to copy the file back to the location. If you check the error number on the IOException that is triggered, you will probably see that it is 13, which is a write permissions error.