##急,简单,怎么复制一个文件 我E盘下有个DBF文件,我想复制到F盘去怎么实现哟,我发现FILE类没有相应的方法,我renameTo结果就变成减切了,急谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那就读入E:\DBF文件,然后写出F:\DBFimport 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();} }} 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){} 对啊,就是读写文件吗。先读到FileInputStream中,然后用FileOutputStream进行写文件操作。 麻烦,用这个多好<copy file="E:\DBF" tofile="F:\DBF"/> <copy file="E:\DBF" tofile="F:\DBF"/>是什么代码??请问 dztc() 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; } } project > build automatically 这个是什么意思?? 求可以实现功能的ftp客户端源程序 一个字符串处理的问题,谢谢大家 Applet 小程序问题 咨询基础问题~ rollback执行了,但数据库数据却不对,WHY? 有愿意帮我看一下程序的解决方法,我是一个很菜的新手:) 关于synchronized方法的探讨! 请教各位网友有关repaint,update和paint方法的用法!谢谢! JAVA高手 一个java游戏,急,(1) 最好的java反编译工具是什么?
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();}
}
}
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){}
用这个多好<copy file="E:\DBF" tofile="F:\DBF"/>
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;
}
}