simplify write(string str) function by using str.getBytes()