高手请进!关于文件复制的问题?
我想实现将F盘的一个文件复制的到E盘,不知道我错在哪里,没有成功。请高手帮忙看一下。
代码如下:
package src;
import java.io.*;
public class CopyFile
{
public static void copy(String src,String dest)
{
try
{
FileInputStream infile=new FileInputStream(src);
InputStreamReader x=new InputStreamReader(infile);
BufferedReader y=new BufferedReader(x);
File newfile=new File(dest);
if(!newfile.exists())
{
newfile.createNewFile();
FileOutputStream outfile=new FileOutputStream(newfile);
OutputStreamWriter j=new OutputStreamWriter(outfile);
BufferedWriter m=new BufferedWriter(j);
String s;
while((s=y.readLine())!=null)
{
m.write(s);
}
outfile.close();
}
infile.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String arg[])
{
String src= "f:\\4.txt ";
String dest= "e:\\5.txt ";
copy(src,dest);
}
}
------解决方案--------------------