BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream(files), "GBK"));
try {
signDir = in.readLine();
file = new File(signDir);
if (file.isDirectory()) {
flag = true;
} else {
flag = false;
}
} catch (IOException e) {
System.out.println("输入错误,请重新输入。");
}
} while (false == flag);
}
private void copyFile(File[] files) {
System.out.println("拷贝的源文件夹路径:" + sourceDir);
System.out.println("拷贝的目标文件夹路径:" + signDir);
for (File f : files) {
try {
File ok = new File(signDir, f.getName());
if (false == ok.exists()) {
ok.createNewFile();
}
FileInputStream fis = new FileInputStream(f);
byte[] size = new byte[(int) f.length()];
fis.read(size);
FileOutputStream fos = new FileOutputStream(ok);
fos.write(size);
if ((f.getName().equals(ok.getName())) && (f.length() == ok.length())) {
System.out.println(f + "\t文件拷贝成功!");
} else {
System.out.println(f + "\t文件拷贝失败!");
}
fis.close();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("文件(夹)没有找到!");
} catch (IOException e) {
System.out.println("文件读取出错!");
}
}
}
}
复制代码
运行报出源文件夹拒绝访问异常
请输入源目录:
Exception in thread "main" java.io.FileNotFoundException: D:\360Rec (拒绝访问。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at com.yan.eight.FileCopy.inputSourceDir(FileCopy.java:45)
at com.yan.eight.FileCopy.<init>(FileCopy.java:29)
at com.yan.eight.FileCopy.main(FileCopy.java:25)
这是怎么回事