[Java] java 文件合并 →→→→→进入此内容的聊天室

来自 , 2020-09-25, 写在 Java, 查看 181 次.
URL http://www.code666.cn/view/ebd9629f
  1. import java.io.*;
  2.  
  3. public class FiletoJpg {
  4.         /**
  5.          *
  6.          * @param jpgPath
  7.          *            原始文件
  8.          * @param filePath
  9.          *            要追加的文件
  10.          * @return
  11.          */
  12.         public static boolean toJpg(String jpgPath, String filePath) {
  13.                 try {
  14.                         RandomAccessFile randomFile = new RandomAccessFile(jpgPath, "rw");
  15.                         FileInputStream fls = new FileInputStream(new File(filePath));
  16.                         byte[] b = new byte[fls.available()];
  17.                         fls.read(b);
  18.                         long l = randomFile.length();
  19.                         // 将指针移到末尾
  20.                         randomFile.seek(l);
  21.                         randomFile.write(b);
  22.                         fls.close();
  23.                         randomFile.close();
  24.                         return true;
  25.                 } catch (IOException e) {
  26.                         System.out.println(e);
  27.                 }
  28.  
  29.                 return false;
  30.         }
  31. }

回复 "java 文件合并"

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

captcha