Problem with System.IO.File

  • Thread starter Thread starter liran
  • Start date Start date
L

liran

hello
i am trying to create a new file and then to write to it. how can i
create an new file? i tried System . IO.File but it returns an error
as follows:
System.IO.File.File() is inaccessible due to its protection level
 
There are a bit many ways to create a file. Here's one

FileStream fileStream = System.IO.File.Create("example.txt");
fileStream.Write(0xFF);

the FileStream's write methods though really only allow you to write byte
and arrays of bytes to the stream, if you wanna write strings you can use a
StreamWriter along with the file stream;

StreamWriter writer = new StreamWriter(fileStream);
writer.Write("Hello ");
writer.WriteLine("World !");

HTH
Cordell Lawrence
Teleios Systems Ltd.
 
Back
Top