文件拷贝问题

flashroom 2003-12-02 09:46:37
JAVA中如何时间文件拷贝?
要先读出原文件然后写进目标文件吗??
以前没接触过

c:\a.dat
->
d:\a.dat

怎么写?谢谢
...全文
37 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
flashroom 2003-12-02
  • 打赏
  • 举报
回复
还是十分谢谢你,加分!
flashroom 2003-12-02
  • 打赏
  • 举报
回复
谢谢,我已经写好了,我是这样。。。。

try{
DataInputStream din=new DataInputStream(new FileInputStream(frompath));
DataOutputStream dout=new DataOutputStream(new FileOutputStream(topath));
byte data[]=new byte[din.available()];
din.read(data);
dout.write(data);
din.close();
dout.close();
}catch(Exception e){
e.printStackTrace();
}


我本来想找一个类似COPY的方法。。。。呵呵
qm0445 2003-12-02
  • 打赏
  • 举报
回复
import java.io.*;
class showfile{
public static void main(String args[])
throws IOException{
int i;
FileInputStream fin;
FileOutputStream fout;
PrintWriter pw=new PrintWriter(System.out,true);
try{
fin=new FileInputStream("jct.txt");
}catch(FileNotFoundException exc){
pw.println("File not found");
return;
}
try{
fout=new FileOutputStream("test.txt");
}catch(FileNotFoundException exc){
pw.println("file not found");
return;
}
do{
i=fin.read();
if(i!=-1) fout.write(i);
}while(i!=-1);
fin.close();
fout.close();
}
}

这是拷贝文件的java 原程序,希望对你有帮助

62,614

社区成员

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

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