to avoid opened files limit, write together in the end.