Solved

copy a binary file to another file not exist before

Posted on 2009-07-06
3
328 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

791 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