View Full Version : کار با فایل ها در #C
  
ermia2008
سه شنبه 23 مرداد 1386, 17:31 عصر
سلام به همگی. لطفا اگه کسی کار با فایل ها در #C رو بلده یه مثال برای طرز خوندن ونوشتن تو فایل برام بفرسته.ممنون.
PC2st
سه شنبه 23 مرداد 1386, 17:43 عصر
برای خواندن از یک فایل متنی از متد System.IO.File.ReadAllLines یا System.IO.File.ReadAllText و برای نوشتن در یک فایل متنی، از متد System.IO.File.WriteAllLines یا System.IO.File.WriteAllText استفاده کنید.
rasoul_ras
سه شنبه 23 مرداد 1386, 17:57 عصر
http://barnamenevis.org/forum/attachment.php?attachmentid=10291&d=1187094384
البته کار با فایلهای bmp
MH2538
چهارشنبه 24 مرداد 1386, 10:52 صبح
سلام
مثال خود MSDN
using System;
using System.IO;
class Test 
{
    public static void Main() 
    {
        string path = @"c:\temp\MyTest.txt";
        if (!File.Exists(path)) 
        {
            // Create a file to write to.
            using (StreamWriter sw = File.CreateText(path)) 
            {
                sw.WriteLine("Hello");
                sw.WriteLine("And");
                sw.WriteLine("Welcome");
            }	
        }
        // Open the file to read from.
        using (StreamReader sr = File.OpenText(path)) 
        {
            string s = "";
            while ((s = sr.ReadLine()) != null) 
            {
                Console.WriteLine(s);
            }
        }
        try 
        {
            string path2 = path + "temp";
            // Ensure that the target does not exist.
            File.Delete(path2);
            // Copy the file.
            File.Copy(path, path2);
            Console.WriteLine("{0} was copied to {1}.", path, path2);
            // Delete the newly created file.
            File.Delete(path2);
            Console.WriteLine("{0} was successfully deleted.", path2);
        } 
        catch (Exception e) 
        {
            Console.WriteLine("The process failed: {0}", e.ToString());
        }
    }
}
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.