We report the effect of annealing on the superconductivity of MgB2 thin films as functions of the postannealing temperature in the range from 700 C to 950 C and of the postannealing time in the range from 30 min to 120 min. On annealing at 900 C for 30 min, we obtained the best-quality MgB2 films with a transition temperature of 39 K and a critical current density of ~ 10^7 A/cm^2. Using the scanning electron microscopy, we also investigated the film growth mechanism. The samples annealed at higher temperatures showed the larger grain sizes, well-aligned crystal structures with preferential orientations along the c-axis, and smooth surface morphologies. However, a longer annealing time prevented the alignment of grains and reduced the superconductivity, indicating a strong interfacial reaction between the substrate and the MgB2 film.