byte数组与文件的转换

来源:互联网 发布:淘宝客营销案例 编辑:程序博客网 时间:2024/06/05 16:29
文件转数组 java.io.InputStream privatekey1 = ActiveService.class.getResourceAsStream(securityClspath);
 ByteArrayOutputStream swapStream1 = new ByteArrayOutputStream();           byte[] buff1 = new byte[2];           int rc1 = 0;           while ((rc1 = privatekey1.read(buff1, 0, 2)) > 0) {               swapStream1.write(buff1, 0, rc1);           }            b1 = swapStream1.toByteArray();          System.out.println(Arrays.toString(b1)); 
数组转文件    OutputStream out = new FileOutputStream(path);         ByteArrayInputStream is = new ByteArrayInputStream(decryptedData1);         byte[] buf = new byte[2];         int len = 0;         while((len=is.read(buf))!=-1){             out.write(buf, 0, len);         }         is.close();         out.close();