byte数组与文件的转换

	文件转数组	 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();

你可能感兴趣的:(java)