java服务器备份(复制)

Java相关内容转载
该博客为转载内容,转载自https://www.cnblogs.com/ytsbk/p/10550595.html ,原内容可能与Java相关。

 

public ResponseResult serverBackup (String[] datypeid)throws IOException{
ResponseResult rr = new ResponseResult();
Properties props = new Properties();
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");
props.load(inputStream);
String oldrootPath = props.getProperty("material");
String rootPath = props.getProperty("backupAddress");
List<String> affixIdList = affixService.getAffixId(datypeid);
List<String> affixPathList = new ArrayList<>();
for(int i = 0;i< affixIdList.size();i++){
String path = affixService.getAffixPath(affixIdList.get(i));
if(path != null){
affixPathList.add(path);
}
}
for(int j = 0 ; j < affixPathList.size();j++){
FileInputStream fis
= new FileInputStream(new java.io.File(affixPathList.get(j)));
BufferedInputStream bis
= new BufferedInputStream(fis);
String newPath = affixPathList.get(j).replace(oldrootPath,rootPath);
java.io.File newFile = new java.io.File(newPath);
if( !newFile.getParentFile().exists()) {
newFile.getParentFile().mkdirs();
}
FileOutputStream fos
= new FileOutputStream(newFile);
BufferedOutputStream bos
= new BufferedOutputStream(fos);
int d = -1;
while((d = bis.read())!=-1){
bos.write(d);
}
bis.close();
bos.close();
}
rr.setMessage("success");
rr.setState(1);
return rr;
}

---恢复内容结束---

转载于:https://www.cnblogs.com/ytsbk/p/10550595.html

Java文件夹复制(远程复制(网络传输),用于远程备份文件)(支持文件夹,嵌套子文件夹) import java.io.*; import java.util.*; public class FileSelection { private File rootDirectory;//根目录 private File[] fileList;//文件目录下面的文件列表(包括目录,用于多次判断) private ArrayList fileArrayList; // 用于存储文件(只是文件)列表 //初始化参数 public FileSelection() { fileArrayList=new ArrayList(); rootDirectory = new File("Test"); rootDirectory.mkdir(); } //获得文件(不包括目录)的列表 public void initFileArrayList() { if (rootDirectory.isDirectory()) { //遍历目录下面的文件和子目录 fileList = rootDirectory.listFiles(); for (int i = 0; i < fileList.length; i++) { //如果是文件,添加到文件列表中 if(fileList[i].isFile()){ fileArrayList.add(fileList[i]); } //否则递归遍历子目录 else if (fileList[i].isDirectory()) { fileList[i].mkdir(); rootDirectory=fileList[i]; initFileArrayList(); } } } } //将文件信息添加到列表中 public void addFiles(File f){ fileArrayList.add(f); } //访问器返回文件列表 public ArrayList getFileArrayList() { return fileArrayList; } } -------------------- BackupClient.java package com.xinxin.Client; import java.io.*; import java.net.*; /** * * @author Administrator *@version 1.0 *BackupClient类实现文件的传输到服务器 */ public class BackupClient implements Runnable{ private int port;//服务器端口 private InetAddress ipAddress;//服务器IP地址 private Socket clientSocket;//客户端套接字 private InputStream inputStream;//网络输入流 private OutputStream outputStream;//网络输出流 private File file; //构造函数(获得服务器端IP地址和监听端口号) public BackupClient(InetAddress ipAddress,int port,File file){ this.ipAddress=ipAddress; this.port=port;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值