Solved

copy a binary file to another file not exist before

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

636 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