Csharp/C Sharp/File Stream/Path — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 11:45, 26 мая 2010

Path.GetTempFileName

 
using System;
using System.IO;
class MainClass {
    static void Main() {
        string tempFile = Path.GetTempFileName();
        Console.WriteLine("Using " + tempFile);
        using (FileStream fs = new FileStream(tempFile, FileMode.Open)) {
            // (Write some data.)
        }
        // Now delete the file.
        File.Delete(tempFile);
    }
}


Paths in C#

 
/*
s = new FileStream("C:\\temp\\Goo.txt", FileMode.Create);
or use forward (Unix-style) slashes:
s = new FileStream("C:/temp/Goo.txt", FileMode.Create);
or use the at sign (@), which is a control-character suppressor:
s = new FileStream(@"C:\temp\Goo.txt", FileMode.Create);
*/


Use static methods in Path

 
using System;
using System.Diagnostics;
using System.IO;
class TestPathApp {
    static void Main(string[] args) {
        Process p = Process.GetCurrentProcess();
        ProcessModule pm = p.MainModule;
        string s = pm.ModuleName;
        Console.WriteLine(Path.GetFullPath(s));
        Console.WriteLine(Path.GetFileName(s));
        Console.WriteLine(Path.GetFileNameWithoutExtension(s));
        Console.WriteLine(Path.GetDirectoryName(Directory.GetCurrentDirectory()));
        Console.WriteLine(Path.GetPathRoot(Directory.GetCurrentDirectory()));
        Console.WriteLine(Path.GetTempPath());
        Console.WriteLine(Path.GetTempFileName());
    }
}