网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java实现文件备份代码 java实现数据库备份

java 备份程序

import java.io.*;

创新互联建站2013年至今,先为遂昌等服务建站,遂昌等地企业,进行企业商务咨询服务。为遂昌企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

public class MyCopy {

public static void main(String args[]){

try {

MyCopy j = new MyCopy(); j.CopyFile(new File(args[0]),new File(args[1]));

}

catch (Exception e) {

e.printStackTrace();

}

}

public void CopyFile(File in, File out) throws Exception {

FileInputStream fis = new FileInputStream(in);

FileOutputStream fos = new FileOutputStream(out);

byte[] buf = new byte[1024];

int i = 0;

while((i=fis.read(buf))!=-1) {

fos.write(buf, 0, i);

}

fis.close();

fos.close();

}

}

// 程序运行时的命令语法为:

// javac MyCopy.java (sourcefile) (destfile)

// java MyCopy.java c:\1.txt d:\1.txt

// 当然前提c盘1.txt 已存在。

java里面的sql数据库备份代码怎么写的?

直接用SQL语句(完全备份):

backup

database

数据库

to

disk='c:\你的备份文件名'

怎样使用java代码实现数据库表的自动备份

将MySql中的数据库导出到文件中 备份

import java.io.*;

import java.lang.*;

public class BeiFen {

public static void main(String[] args) {

// 数据库导出

String user = "root"; // 数据库帐号

String password = "root"; // 登陆密码

String database = "test"; // 需要备份的数据库名

String filepath = "e:\\test.sql"; // 备份的路径地址

String stmt1 = "mysqldump " + database + " -u " + user + " -p"

+ password + " --result-file=" + filepath;

/*

* String mysql="mysqldump test -u root -proot

* --result-file=d:\\test.sql";

*/

try {

Runtime.getRuntime().exec(stmt1);

System.out.println("数据已导出到文件" + filepath + "中");

}

catch (IOException e) {

e.printStackTrace();

}

}

}

将数据从磁盘上的文本文件还原到MySql中的数据库

import java.io.*;

import java.lang.*;

/*

* 还原MySql数据库

* */

public class Recover {

public static void main(String[] args) {

String filepath = "d:\\test.sql"; // 备份的路径地址

//新建数据库test

String stmt1 = "mysqladmin -u root -proot create test";

String stmt2 = "mysql -u root -proot test " + filepath;

String[] cmd = { "cmd", "/c", stmt2 };

try {

Runtime.getRuntime().exec(stmt1);

Runtime.getRuntime().exec(cmd);

System.out.println("数据已从 " + filepath + " 导入到数据库中");

} catch (IOException e) {

e.printStackTrace();

}

}

}

JAVA题目 编写一个程序,用于实现文件的备份,程序运行时的命令语法为:

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.nio.channels.FileChannel;

public class mycopy {

public static void main(String[] args) {

if (args.length != 2) {

System.out.println("Usage: Java mycopy〈sourcefile〉〈destfile〉");

System.exit(0);

}

File sourcefile = new File(args[0]);

if (!sourcefile.exists()) {

System.out.println("sourcefile: " + args[0] + " not exists");

System.exit(0);

}

FileChannel srcChannel = null;

FileChannel dstChannel = null;

try {

srcChannel = new FileInputStream(args[0]).getChannel();

dstChannel = new FileOutputStream(args[1]).getChannel();

dstChannel.transferFrom(srcChannel, 0, srcChannel.size());

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

srcChannel.close();

dstChannel.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

需要jdk1.4的支持


当前名称:java实现文件备份代码 java实现数据库备份
网页地址:http://bjjierui.cn/article/hipsdp.html

其他资讯