Main.java 2.12 KB

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Main {
    private static String pkgName;
    private static String versionCode;
    private static String versionName;
    private static String url;
    private static String md5;

    public static void main(String[] args) {
        File file = null;
        System.out.println("hello world");
        if(args != null) {
            for (String arg : args) {
                System.out.println("arg:" + arg);
                file = new File(arg);
            }
        }
        if(file != null) {
            String result = readToString(file);
            System.out.println("result:" + result);
            String[] commands = result.split("\\n");
            pkgName = commands[0];
            versionCode = commands[1];
            versionName = commands[2];
            url = commands[3];
            md5 = commands[4];
            JSONObject object = new JSONObject();
            try {
                object.put("pkgName", pkgName);
                object.put("versionCode", versionCode);
                object.put("versionName", versionName);
                object.put("url", url);
                object.put("md5", md5);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            OKHttpUtils.commonPost("http://172.16.29.42:8080/insertApkInfo", object.toString());
        }
    }

    private static String readToString(File file) {
        String encoding = "UTF-8";
        Long filelength = file.length();
        byte[] filecontent = new byte[filelength.intValue()];
        try {
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            return new String(filecontent);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}