一般来说java开发都是在windows开发,但是实际部署项目会部署到linux系统上,因此在文件夹的操作上面会有不同的地方
在windows环境下
String pathRf = UrlUtil.getUrlUtil().getPrjpth();
Date date=new Date();//获取当前日期也可以用Calendar.getInstance();
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String f_date=sdf1.format(date);
pathTo = pathTo+"\\"+new Date().getTime();
File file = new File(pathTo);
if(!file.exists()){
file.mkdirs(); //新建文件夹
}
Runtime run=Runtime.getRuntime();
Process p=null;
p=run.exec("xcopy /s/y/i/f \"" +pathRf+"\" \""+pathTo+"\"");
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
在linux环境下
String pathTo = UrlUtil.getUrlUtil().getBackuppth();
String pathRf = UrlUtil.getUrlUtil().getPrjpth();
Date date=new Date();//获取当前日期也可以用Calendar.getInstance();
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String f_date=sdf1.format(date);
String separator = File.separator;
String directory = pathTo + separator + new Date().getTime();
File file = new File(directory);
if(!file.exists()){
file.mkdirs(); //新建文件夹
}
Runtime run=Runtime.getRuntime();
Process p=null;
p=run.exec("cp -fpr " +pathRf+" "+pathTo);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}