[Java] 文件操作--复制文件 →→→→→进入此内容的聊天室

来自 , 2019-07-27, 写在 Java, 查看 117 次.
URL http://www.code666.cn/view/7949e456
  1.         public static void CopyFile(String oldPath, String newPath) {
  2.                 try {
  3.                         int bytesum = 0;
  4.                         int byteread = 0;
  5.                         File oldfile = new File(oldPath);
  6.                         if (oldfile.exists()) { // 文件存在时
  7.                                 InputStream inStream = new FileInputStream(oldPath); // 读入原文件
  8.                                 FileOutputStream fs = new FileOutputStream(newPath);
  9.                                 byte[] buffer = new byte[1444];
  10.                                 while ((byteread = inStream.read(buffer)) != -1) {
  11.                                         bytesum += byteread; // 字节数 文件大小
  12.                                         System.out.println(bytesum);
  13.                                         fs.write(buffer, 0, byteread);
  14.                                 }
  15.                                 inStream.close();
  16.                         }
  17.                 } catch (Exception e) {
  18.                         System.out.println("复制单个文件操作出错");
  19.                         e.printStackTrace();
  20.                 }
  21.         }

回复 "文件操作--复制文件"

这儿你可以回复上面这条便签

captcha