admin管理员组文章数量:1613754
一般来说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);
}
版权声明:本文标题:windows和linux环境中java新建文件夹和执行复制文件的操作 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728658808a1168464.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论