Solved

copy a binary file to another file not exist before

Posted on 2009-07-06
3
332 Views
Last Modified: 2012-05-07
Hi expert,

In MySql database, I have a binary file name carrier.myd. Since I'll delete this content file, and write new content to this file. To do that, I want to back up my carrier.myd to another file name. If in case something is wrong, I can use this new file name to back up the old data.
In C#, how can I make copy of this carrier.myd to a non existed file name?

Thanks,
JT

0
Comment
Question by:jtran007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
vaibhav_dw earned 500 total points
ID: 24791627
Hi JT

You can do something like as that provided in the code snippet.
I've assumed the path of the files. I've simply read and writen the binary files.

FileStream f = new FileStream("d://carrier.myd", FileMode.Open);
	long length = f.Length;
        FileStream fbackup = new FileStream("d://backup//carrier.myd", FileMode.Create);
        BinaryReader br = new BinaryReader(f); 
        BinaryWriter bwbackup = new BinaryWriter(fbackup);
 
        byte[] buffer = br.ReadBytes(int.Parse(length.ToString()));
        bwbackup.Write(buffer);
 
        f.Close();
        fbackup.Close();
        br.Close();
        bwbackup.Close();

Open in new window

0
 
LVL 5

Expert Comment

by:Pablissimo
ID: 24791890
Path.GetRandomFilename() will give you a random filename that you could use - the filename it generates will be incredibly unlikely to match any existing file in your directory.
0
 

Author Closing Comment

by:jtran007
ID: 31600453
Thks,
JT
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question