set the_file to (((path to desktop) as string) & "test.txt") as file specification
set the_data to "Hey there" as string
try
open for access the_file with write permission
set eof of the_file to 0
write (the_data) to the_file starting at eof
close access the_file
on error
try
close access the_file
end try
end try
set read_data to read the_file