Csharp/CSharp Tutorial/File Directory Stream/File Create — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:20, 26 мая 2010
Create a file and get its creation time, full name and Attributes
using System;
using System.IO;
public class MainClass
{
public static int Main(string[] args)
{
FileInfo f = new FileInfo(@"C:\Test.txt");
FileStream fs = f.Create();
Console.WriteLine("Creation: {0}", f.CreationTime);
Console.WriteLine("Full name: {0}", f.FullName);
Console.WriteLine("Full atts: {0}", f.Attributes.ToString());
fs.Close();
f.Delete();
return 0;
}
}
Create text file using File.CreateText
using System;
using System.IO;
class MainClass
{
static void Main(string[] args)
{
StreamWriter MyStream = null;
string MyString = "Hello World";
try
{
MyStream = File.CreateText("MyFile.txt");
MyStream.Write(MyString);
}
catch (IOException e)
{
Console.WriteLine(e);
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
if (MyStream != null)
MyStream.Close();
}
}
}
Creating Files
using System;
using System.IO;
public class MainClass
{
public static void Main()
{
FileInfo MyFile = new FileInfo(@"c:\Test.txt");
MyFile.Create();
}
}