您好我需要使用java 7 copyfilemethod将存储在数组中的文件复制到目标文件夹中。我没有得到任何错误,但它没有复制文件。请帮助将文件从源文件复制到目标文件夹。谢谢提前 公共类copyFiles {
public static void main(String[] args) {
Date date = new Date(); // your date
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
String date2 = ((month+1) + "/" + (day) + "/" + year);
System.out.println("the current date is " + date2);
String path = "c://Users//Desktop//Test";
System.out.println("PATH::"+path);
File directory = new File(path);
File[] myarray;
myarray = directory.listFiles();
try{
for (int j = 0; j < myarray.length; j++) {
if(myarray[j].isDirectory()){
SimpleDateFormat sdf = new SimpleDateFormat("M/D/YY");
String dt = sdf.format(myarray[j].lastmodified());
if(dt.compareTo(date2) == 0){
File[] myarray1 - myarray[j].listFiles();
for(int i = 0; i < myarray1,length; i++){
if(myarray1[i].isDirectory()){
System.out.println("Do nothing");
}
else
{
SimpleDateFormat sdf1 = new SimpleDateFormat("M/D/YYYY");
String dt1 = sdf1.format(myarray1[i].lastmodified());
if(dt1.compareTo(date2) == 0){
System.out.println(myarray1[i]);
File Source = myarray1[i];
File Dest = new File("c://Users//Desktop//destination");
CopyFileusingJava7Files(source, dest);
}
}
}
}
}
}
}
catch(Exception e){
System.out.println("The file is not found");
}
}
Private Static void CopyFileusingJava7Files(File source, File dest) throws IOException{
Files.copy(source.toPath(), dest.toPath());
}}
答案 0 :(得分:0)
尝试使用管理权限。通常情况下,除非您定义所需的权限,否则JAR没有那么多权利。
我将在下面分享一些有趣的链接,您可以在其中找到有关定义权限的信息。这可以通过文件:“MANIFEST.MF”。