www.digitalmars.com         C & C++   DMDScript  

D - FileMode.Out should create a new file

Is there a good reason why creating a new File with FileMode.Out will only
open and existing file ?
surely the default settings should be
FileMode.In (only open an existing file)
FileMode.Out (create new or truncate existing)
FileMode.In | FileMode.Out (create new set the read/write pointer to the
begin of the file)

I feel that File should have a constructor that takes 3 params (path,
FileMode, FileCreateMode )
the FileCreateMode would be from the following
Default, OpenExisting, OpenAppend
or have the fopen style "r","w","a", "r+", "w+", "a+"

if the File is  created with just FileMode.In then OpenExisting is set (I
see no reason to ever want to read from a file that does not exist)

example to show the "problem"

import stream;
int main( char[][] args )
{
 try {
 Stream output;
 output = new File( "test.txt", FileMode.Out );
 } catch (Exception e ) {
  printf("Exception caught:\n");
  e.print();
 }
 return 0;
}

Mike.
Oct 01 2002