نمایش نتایج 1 تا 4 از 4

نام تاپیک: اشکال در ذخیره سازی فایل پس از ویرایش

  1. #1

    Question اشکال در ذخیره سازی فایل پس از ویرایش

    سلام خدمت اساتید عزیز
    یک برنامه نوشتم که با فایل های مختلف کار کنه، اما زمانی که فایل رو پس از باز کردن درون یک آرایه از جنس بایت می ریزم و پس از ویرایش ذخیره می کنم فایل رو به صورت خراب ذخیره می کنه و دیگه نمیشه ازش استفاده کرد. لطفا به من راهنمایی بدید.
    با تشکر مجتبی

  2. #2

    نقل قول: اشکال در ذخیره سازی فایل پس از ویرایش

    منظورت فايل txt هست؟

  3. #3

    نقل قول: اشکال در ذخیره سازی فایل پس از ویرایش


  4. #4

    نقل قول: اشکال در ذخیره سازی فایل پس از ویرایش

    یعنی با این متد کار کردی و مشکل پیدا کردی؟
    File.WriteAllBytes(string path, byte[] bytes)


    با BinaryWriter و BinaryReader کار کن:

    using System;
    using System.IO;
    using System.Security.Permissions;

    // Store and retrieve application settings.
    class AppSettings
    {
    const string fileName = "AppSettings#@@#.dat";
    float aspectRatio;
    string lookupDir;
    int autoSaveTime;
    bool showStatusBar;

    public AppSettings()
    {
    // Create default application settings.
    aspectRatio = 1.3333F;
    lookupDir = @"C:\AppDirectory";
    autoSaveTime = 30;
    showStatusBar = false;

    if(File.Exists(fileName))
    {
    BinaryReader binReader =
    new BinaryReader(File.Open(fileName, FileMode.Open));
    try
    {
    // If the file is not empty,
    // read the application settings.
    // First read 4 bytes into a buffer to
    // determine if the file is empty.
    byte[] testArray = new byte[3];
    int count = binReader.Read(testArray, 0, 3);

    if (count != 0)
    {
    // Reset the position in the stream to zero.
    binReader.BaseStream.Seek(0, SeekOrigin.Begin);

    aspectRatio = binReader.ReadSingle();
    lookupDir = binReader.ReadString();
    autoSaveTime = binReader.ReadInt32();
    showStatusBar = binReader.ReadBoolean();
    }
    }

    // If the end of the stream is reached before reading
    // the four data values, ignore the error and use the
    // default settings for the remaining values.
    catch(EndOfStreamException e)
    {
    Console.WriteLine("{0} caught and ignored. " +
    "Using default values.", e.GetType().Name);
    }
    finally
    {
    binReader.Close();
    }
    }

    }

    // Create a file and store the application settings.
    public void Close()
    {
    using(BinaryWriter binWriter =
    new BinaryWriter(File.Open(fileName, FileMode.Create)))
    {
    binWriter.Write(aspectRatio);
    binWriter.Write(lookupDir);
    binWriter.Write(autoSaveTime);
    binWriter.Write(showStatusBar);
    }
    }

    public float AspectRatio
    {
    get{ return aspectRatio; }
    set{ aspectRatio = value; }
    }

    public string LookupDir
    {
    get{ return lookupDir; }
    set{ lookupDir = value; }
    }

    public int AutoSaveTime
    {
    get{ return autoSaveTime; }
    set{ autoSaveTime = value; }
    }

    public bool ShowStatusBar
    {
    get{ return showStatusBar; }
    set{ showStatusBar = value; }
    }
    }

    class Test
    {
    static void Main()
    {
    // Load application settings.
    AppSettings appSettings = new AppSettings();
    Console.WriteLine("App settings:\nAspect Ratio: {0}, " +
    "Lookup directory: {1},\nAuto save time: {2} minutes, " +
    "Show status bar: {3}\n",
    new Object[4]{appSettings.AspectRatio.ToString(),
    appSettings.LookupDir, appSettings.AutoSaveTime.ToString(),
    appSettings.ShowStatusBar.ToString()});

    // Change the settings.
    appSettings.AspectRatio = 1.250F;
    appSettings.LookupDir = @"C:\Temp";
    appSettings.AutoSaveTime = 10;
    appSettings.ShowStatusBar = true;

    // Save the new settings.
    appSettings.Close();
    }
    }

تاپیک های مشابه

  1. ذخیره سازی فایل در بانک
    نوشته شده توسط کم حوصله در بخش تحلیل و طراحی بانک اطلاعات
    پاسخ: 6
    آخرین پست: شنبه 07 بهمن 1391, 09:48 صبح
  2. اشکال در ذخیره سازی مشخصات فایل در دیتابیس
    نوشته شده توسط veniz2008 در بخش ASP.NET Web Forms
    پاسخ: 1
    آخرین پست: شنبه 14 خرداد 1390, 20:13 عصر
  3. ذخیره سازی فایل عکس در بانک
    نوشته شده توسط کم حوصله در بخش مطالب مرتبط با بانکهای اطلاعاتی در VB6
    پاسخ: 16
    آخرین پست: پنج شنبه 08 مهر 1389, 08:09 صبح
  4. نیاز به الگوریتم ذخیره سازی فایل bmp
    نوشته شده توسط zehs_sha در بخش الگوریتم، کامپایلر، هوش مصنوعی و ساختمان داده ها
    پاسخ: 3
    آخرین پست: شنبه 21 شهریور 1383, 13:31 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •