RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
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://scyingshan.cn/article/hipsdp.html