Main.java
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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;
}
}