Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.web.controller; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; /** * @author liubinqiang * @date 2017-2-6 10:17:43 * @version V1.0 * @desc */ @Controller public class ToolController { @RequestMapping("/tool/app") public String app() { return "app"; } @ResponseBody @RequestMapping(value = "/tool/verifyapk", method = RequestMethod.POST) public String verifyApk(@RequestParam("apkfile") MultipartFile file) { //keytool -list -printcert -jarfile d:\weixin653android980.apk //keytool -printcert -file D:\testapp\META-INF\CERT.RSA //System.out.println("12345"); try { OutputStream stream = new FileOutputStream(new File(file.getOriginalFilename())); BufferedOutputStream outputStream = new BufferedOutputStream(stream); outputStream.write(file.getBytes()); outputStream.flush(); outputStream.close(); Runtime runtime = Runtime.getRuntime(); String ccString = "keytool -list -printcert -jarfile C:\\Users\\Administrator\\Desktop\\zju1.1.8.2.apk"; Process p = runtime.exec(ccString); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); StringBuilder sb = new StringBuilder(); while (br.readLine() != null) { sb.append(br.readLine() + "<br/>"); } p.destroy(); p = null; return sb.toString(); } catch (FileNotFoundException fe) { return fe.getMessage(); } catch (IOException ioe) { return ioe.getMessage(); } } }