PDF to byte array and vice versa

前端 未结 13 1261
独厮守ぢ
独厮守ぢ 2020-11-27 04:19

I need to convert pdf to byte array and vice versa.

Can any one help me?

This is how I am converting to byte array

public static byte[] conve         


        
13条回答
  •  天命终不由人
    2020-11-27 04:46

    I have implemented similiar behaviour in my Application too without fail. Below is my version of code and it is functional.

        byte[] getFileInBytes(String filename) {
        File file  = new File(filename);
        int length = (int)file.length();
        byte[] bytes = new byte[length];
        try {
            BufferedInputStream reader = new BufferedInputStream(new 
        FileInputStream(file));
        reader.read(bytes, 0, length);
        System.out.println(reader);
        // setFile(bytes);
    
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        return bytes;
        }
    

提交回复
热议问题