public static boolean CopyFile(String src1, String des1) throws IOException {// 判断传入地址是否有效 if(src1 == null || src1 == "" || des1 == null || des1 == ""){ System.out.println("您输入的是无效地址"); return false; }// 创建流对象,并使用try(resource...)保证一定会关闭流对象 try( InputStream In = new FileInputStream(new File(src1)); OutputStream Out = new FileOutputStream(new File(des1)) ){// 创建缓冲区 byte [] bs = new byte[8]; int len = 0; while ((len = In.read(bs))!= -1){// 每读一次就写一次 Out.write(bs); } } return true; }
Sign in to make a reply
。。。