将BLOB转换为PDF

时间:2018-10-15 08:40:21

标签: java blob

我有一个来自数据库团队的BLOB文件。我知道它是PDF文档(我使用Notepad ++打开,可以看到文件名),并且需要使用Java进行转换。我已经检查了几个示例,但找不到任何将BLOB文件本身作为输入而不是直接从DB(结果集)中获取的示例。谁能给我一些有关我如何完成此工作的指示?

谢谢!

我在下面尝试过

File file = new File("C:/Users/User1/Desktop/0LK54E33K1477e2MCEU25JV0G8MG418S007N45JU.BLOB0");

        FileInputStream fis = new FileInputStream(file);
        //System.out.println(file.exists() + "!!");
        //InputStream in = resource.openStream();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        try {
            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum); //no doubt here is 0
                //Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
                System.out.println("read " + readNum + " bytes,");
            }
        } catch (IOException ex) {
            //Logger.getLogger(genJpeg.class.getName()).log(Level.SEVERE, null, ex);
        }
        byte[] bytes = bos.toByteArray();

        //below is the different part
        File someFile = new File("C:/Users/User1/Desktop/Test.pdf");
        FileOutputStream fos = new FileOutputStream(someFile);
        fos.write(bytes);
        fos.flush();
        fos.close();

0 个答案:

没有答案