okhttp-peer-certificate-extractor icon indicating copy to clipboard operation
okhttp-peer-certificate-extractor copied to clipboard

can't create File from assets file

Open shakeri-mreza opened this issue 6 years ago • 1 comments

I have my .pem file placed in assets folder. how can I create a java file from it ?

shakeri-mreza avatar Jul 18 '18 00:07 shakeri-mreza

just place it in raw folder instead of assets and use the following code

  InputStream inputStream = MyApplication.getmInstance().getResources().openRawResource(R.raw.ccert);
        File certificate = File.createTempFile("pre", "suf");
        copyFile(inputStream, new FileOutputStream(certificate)); 
    private static void copyFile(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while((read = in.read(buffer)) != -1){
            out.write(buffer, 0, read);
        }
    }

hkawii avatar Aug 26 '18 14:08 hkawii