怎样复制一个文件? 将C:/下的a.txt文件拷贝到D:/下,并改名为b.txt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 File file = new File("a");file.rename() The easiest way is to use CMD commands to copy a file...^_^ 是用IO进行操作吗try{FileInputStream input=new FileInputStream("c//a.txt");}catch(FileNotFoundException e){}FileOutputStream out=new FileOutputStream("d//b.txt");int len;byte[] b=new byte[1024];while((len=input.read(b))!=-1) out.write(b,0,len);input.close();out.close(); 用Java的流的话,像ls的就可以达到效果,但是不建议用1024,建议用int len = file.avaible(),然后读len个长度,一次就ok package first;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class File_copy { public static void main(String[] args) { File file=new File("d:\\b.txt"); FileInputStream fileIn = null; FileOutputStream fileOut = null; byte[] b=new byte[1024]; try { fileIn=new FileInputStream("c:\\a.txt"); fileOut = new FileOutputStream(file); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { while(fileIn.read()!=-1){ fileIn.read(b); fileOut.write(b, 0, b.length); fileOut.flush(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { fileIn.close(); fileOut.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }} 请教 thread 异常 求100到200以内的质数 关于使用 Netbeans 的一个问题。 想要大量的JAVA的原代码 关于测试,急啊,再写不出来领导就要骂了 用JavaMail发送Email,提示被反垃圾邮件系统拒绝!! 刚刚接触java,往各位大虾指点一二--------在线等待 List组件中哪个listener监听列表项下标变化的事件 给定2个时间,如何计算他们之间的天数? 在职跳槽,前辈支个高招!!欢迎讨论!!!进者有分!!! 中文存进数据库就是乱码了~求助 求星期几的问题,帮帮忙谢谢了?????????
file.rename()
try{
FileInputStream input=new FileInputStream("c//a.txt");
}catch(FileNotFoundException e){}
FileOutputStream out=new FileOutputStream("d//b.txt");
int len;
byte[] b=new byte[1024];
while((len=input.read(b))!=-1)
out.write(b,0,len);
input.close();
out.close();
package first;import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;public class File_copy { public static void main(String[] args) {
File file=new File("d:\\b.txt");
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
byte[] b=new byte[1024];
try {
fileIn=new FileInputStream("c:\\a.txt");
fileOut = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while(fileIn.read()!=-1){
fileIn.read(b);
fileOut.write(b, 0, b.length);
fileOut.flush();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fileIn.close();
fileOut.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }}