把文件a.txt复制到指定目录下为a.mp3
package cn.mldn.demo;
import java.io.*;
public class TestDemo{
public static void main(String[] args) throws IOException {
File f1=new File("d:/a.txt");
InputStream fis=new FileInputStream(f1);
File f2=new File("d:/a.mp3");
OutputStream fos=new FileOutputStream(f2);
if(!f1.exists()){
System.out.println("目录不存在!");
}else{
int temp=0;
byte data[]=new byte[1024];
while((temp=fis.read(data))!=-1){
fos.write(data, 0, temp);
}
System.out.println("复制成功!");
}
fis.close();
fos.close();
}
}