某天无聊,写了个拷贝文件的类,简单~


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

public class CopyFile {
 public boolean CopyFile(String sourceFilename, String destinationFilename) {

  try {
   DataInputStream dis = new DataInputStream(
     new FileInputStream(sourceFilename));
   
   int read = dis.read();
   FileOutputStream fqs = new FileOutputStream(destinationFilename);
   while(read != -1) { // -1 stands for endoffile
    fqs.write(read); // write a byte
    read = dis.read(); // read a byte
   }
   dis.close();
   fqs.close();
  } catch (Exception e) {
   System.out.println(e.toString());
   return false;
  }
  return true;
 }
 
 public static void main(String[] args) {
  CopyFile cf = new CopyFile();
  cf.CopyFile("C:\\source.txt", "C:\\destination.txt");
 }
}