- import java.io.*;
- public class FiletoJpg {
- /**
- *
- * @param jpgPath 原始文件
- * @param filePath 要追加的文件
- * @return
- */
- public static boolean toJpg(String jpgPath,String filePath){
- try {
- RandomAccessFile randomFile = new RandomAccessFile(jpgPath, "rw");
- FileInputStream fls = new FileInputStream(new File(filePath));
- byte [] b = new byte[fls.available()];
- fls.read(b);
- long l = randomFile.length();
- //将指针移到末尾
- randomFile.seek(l);
- randomFile.write(b);
- fls.close();
- randomFile.close();
- return true;
- } catch (IOException e) {
- System.out.println(e);
- }
- return false;
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/221020136563.html
来源: http://www.codesnippet.cn/detail/221020136563.html