in reply to how can i open a new file with permission 0666 ?

Hi,
judging from your code you're running on a *nix platform. You should have a look at two things:

HTH - Mark