##急,简单,怎么复制一个文件

skyboy0720 2006-03-31 07:43:26
我E盘下有个DBF文件,我想复制到F盘去
怎么实现哟,我发现FILE类没有相应的方法,我renameTo结果就变成减切了,急
谢谢
...全文
194 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
supersunyi 2006-04-12
  • 打赏
  • 举报
回复
public static boolean copyFile(String srcfile, String destfile) {
try {
File file = new File(destfile);
file.createNewFile();

File iFile = new File(srcfile);
File oFile = new File(destfile);

FileReader in = new FileReader(iFile);
FileWriter out = new FileWriter(oFile);

int c;
while ((c = in.read()) != -1) {
out.write(c);
}

in.close();
out.close();
return true;
} catch (IOException e) {
return false;
}
}
jeffaple 2006-04-12
  • 打赏
  • 举报
回复
ant
hiyu2218 2006-04-12
  • 打赏
  • 举报
回复
<copy file="E:\DBF" tofile="F:\DBF"/>是什么代码??请问 dztc()
dztc 2006-04-12
  • 打赏
  • 举报
回复
麻烦,
用这个多好<copy file="E:\DBF" tofile="F:\DBF"/>
dztc 2006-04-01
  • 打赏
  • 举报
回复
mark
zhigangsun 2006-04-01
  • 打赏
  • 举报
回复
对啊,就是读写文件吗。先读到FileInputStream中,然后用FileOutputStream进行写文件操作。
iwlk 2006-04-01
  • 打赏
  • 举报
回复
读, 写, 就可以实现复制了
lydvqq 2006-03-31
  • 打赏
  • 举报
回复
File newFile = new File(filename);
newFile.createNew();
FileInputStream fis = new FileInputStream(oldFile);
FileOutputStream fos = new FileOutputStream(newFile);
byte[] buf = new byte[1024];
try{
int count = fis.read(buf);
while(count!=-1)
{
fos.write(buf);
count = fis.read(buf);
}}catch(Exception e){}
Fifotom 2006-03-31
  • 打赏
  • 举报
回复
那就读入E:\DBF文件,然后写出F:\DBF

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class Test{
public static void main(String args[])
{
try
{
FileInputStream fis = new FileInputStream("E:\\DBF");
FileOutputStream fos = new FileOutputStream("F:\\DBF");

int tmp;
while(-1 != (tmp=fis.read()))
{
fos.write(tmp);
}
}catch(Exception e){e.printStackTrace();}
}
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧