怎么提示这个呀
java.io.FileNotFoundException: e:\Open_Sourse (拒绝访问。) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:106) at java.io.FileReader.<init>(FileReader.java:55) at CopyFilesDemo.copyFiles(CopyFilesDemo.java:20) at CopyFilesDemo.main(CopyFilesDemo.java:9)Exception in thread "main" java.lang.RuntimeException: 文件复制失败! at CopyFilesDemo.copyFiles(CopyFilesDemo.java:28) at CopyFilesDemo.main(CopyFilesDemo.java:9)
import java.io.*;
class CopyFilesDemo
{
public static void main(String[] args)
{
String sourse = "e:\\Open_Sourse";
String target = "e:\\copy";
copyFiles(sourse,target);
}
public static void copyFiles(String sourse,String target)
{
File sour = new File(sourse);
File targ = new File(target);
Writer fw = null;
BufferedReader fr = null;
try
{
fr = new BufferedReader(new FileReader(sour));
fw = new BufferedWriter(new FileWriter(targ));
copyToFile(sour,targ,fr,fw);
}
catch (IOException e)
{
e.printStackTrace();
throw new RuntimeException("文件复制失败!");
}finally
{
try
{
if(fr != null)
fr.close();
}
catch (IOException efr)
{
efr.printStackTrace();
throw new RuntimeException("读取流关闭失败!");
}
try
{
if(fw != null)
fw.close();
}
catch (IOException efw)
{
efw.printStackTrace();
throw new RuntimeException("写入流关闭失败!");
}
}
}
public static void copyToFile(File sour,File targ,BufferedReader fr,Writer fw) throws IOException
{
File[] files = sour.listFiles();
for(File file : files)
{
if(file.isDirectory())
copyToFile(sour,targ,fr,fw);
else
{
String line = null;
while((line = fr.readLine()) != null)
{
fw.write(line);
fw.flush();
}
}
}
}
}
|