top down design

public class CopyFileDemo {

 public static void main(String[] args) {
  String src=\'#\'" />   String dest = "f:\\1.jpg";
  try {
   copyFile(src, dest);

   System.out.println("拷贝成功");
  } catch (IOException e) {
   System.out.println(e.getMessage());
  }catch (Exception e) {
   System.out.println("未知原因  拷贝失败");
  }
 }

 private static void copyFile(String src, String dest) throws IOException {
  InputStream in = readFile(src);
  writeFile(in, dest);

 }

 private static void writeFile(InputStream in, String dest)
   throws IOException {

  if (!exitFile(dest)) {
   File file = new File(dest);
   file.createNewFile();
  }
  FileOutputStream out = new FileOutputStream(dest);
  inToOut(in, out);

 }

 private static void inToOut(InputStream in, FileOutputStream out)
   throws IOException {
  try {
   int len = 0;
   byte buffer[] = new byte[1024];
   while ((len = in.read(buffer)) > 0) {
    out.write(buffer, 0, len);
   }
  } finally {
   if (in != null) {
    in.close();

   }
   if (out != null) {
    out.close();


   }
  }

 }

 private static InputStream readFile(String src) throws IOException {
  if (!exitFile(src)) {
   throw new FileNotFoundException("制定目标文件不存在");
  }
  FileInputStream fileInputStream = new FileInputStream(src);
  return fileInputStream;
 }

 private static boolean exitFile(String src) {
  File file = new File(src);
  if (file.exists()) {
   return true;
  }
  return false;
 }

}
 

本文出自 “android” 博客,转载请与作者联系!

你可能感兴趣的:(top,职场,design,down,休闲)