项目相关

1. java 调用  exec 执行 命令行程序

复制代码
public static List exec(String command, String filePath) throws IOException {
Process process = Runtime.getRuntime().exec(command + filePath);
List list = new ArrayList();
InputStream in = process.getInputStream();
InputStreamReader isr = null;
BufferedReader ibr = null;
String line = "";
isr = new InputStreamReader(in);
ibr = new BufferedReader(isr);
try {
while ((line = ibr.readLine()) != null) {
list.add(line);
System.out.println(line);
}
} catch (Exception e) {
System.out.println("error");
}
return list;
}
复制代码

2.  list

 

复制代码
public static List readfile(String filepath) throws FileNotFoundException,
IOException {

List list = new ArrayList();

File file = new File(filepath);
if (!file.isDirectory()) {

} else if (file.isDirectory()) {
String[] filelist = file.list();
for (int i = 0; i < filelist.length; i++) {
File readfile = new File(filepath + "\\" + filelist[i]);
if (!readfile.isDirectory()) {

String result = readfile.getName();
list.add(result.replace("\\", ""));
} else if (readfile.isDirectory()) {
readfile(filepath + "\\" + filelist[i]);
}
}
}
return list;
}
复制代码

3.  java 读取 android 的 public key

复制代码
    private static java.security.cert.Certificate[] loadCertificates(JarFile jarFile, JarEntry je, byte[] readBuffer) {
try {
InputStream is = jarFile.getInputStream(je);
while (is.read(readBuffer, 0, readBuffer.length) != -1) {
// not using
}
is.close();
return (java.security.cert.Certificate[]) (je != null ? je.getCertificates() : null);
} catch (IOException e) {
System.err.println("Exception reading " + je.getName() + " in " + jarFile.getName() + ": " + e);
}
return null;
}
private static char[] toChars(byte[] mSignature) {
byte[] sig = mSignature;
final int N = sig.length;
final int N2 = N * 2;
char[] text = new char[N2];

for (int j = 0; j < N; j++) {
byte v = sig[j];
int d = (v >> 4) & 0xf;
text[j * 2] = (char) (d >= 10 ? ('a' + d - 10) : ('0' + d));
d = v & 0xf;
text[j * 2 + 1] = (char) (d >= 10 ? ('a' + d - 10) : ('0' + d));
}
return text;
}

public static List parse(String filepath) throws CertificateEncodingException, IOException {
List list = new ArrayList();
String mArchiveSourcePath = filepath;
WeakReference<byte[]> readBufferRef;
byte[] readBuffer = null;
synchronized (mSync) {
readBufferRef = mReadBuffer;
if (readBufferRef != null) {
mReadBuffer = null;
readBuffer = readBufferRef.get();
}
if (readBuffer == null) {
readBuffer = new byte[8192];
readBufferRef = new WeakReference<byte[]>(readBuffer);
}
}
JarFile jar = new JarFile(mArchiveSourcePath);
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry je = (JarEntry) entries.nextElement();
if (je.isDirectory()) {
continue;
}
if (je.getName().startsWith("META-INF/")) {
continue;
}
}
JarFile jarFile = new JarFile(mArchiveSourcePath);
java.security.cert.Certificate[] certs = null;
Enumeration entries1 = jarFile.entries();
while (entries1.hasMoreElements()) {
JarEntry je = (JarEntry) entries1.nextElement();
if (je.isDirectory()) {
continue;
}
if (je.getName().startsWith("META-INF/")) {
continue;
}
java.security.cert.Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
if (localCerts == null) {
System.err.println("Package has no certificates at entry " + je.getName() + "; ignoring!");
jarFile.close();
return null;
} else if (certs == null) {
certs = localCerts;
} else {
// Ensure all certificates match.
for (int i = 0; i < certs.length; i++) {
boolean found = false;
for (int j = 0; j < localCerts.length; j++) {
if (certs[i] != null && certs[i].equals(localCerts[j])) {
found = true;
break;
}
}
if (!found || certs.length != localCerts.length) {
System.err.println("Package has mismatched certificates at entry " + je.getName() + "; ignoring!");
jarFile.close();
return null; // false
}
}
}
}
jarFile.close();
synchronized (mSync) {
mReadBuffer = readBufferRef;
}
if (certs != null && certs.length > 0) {
final int N = certs.length;
for (int i = 0; i < N; i++) {
String charSig = new String(toChars(certs[i].getEncoded()));
list.add("type:" + certs[i].getType() + ", public key:" + certs[i].getPublicKey() + ", hash code:" + certs[i].hashCode());

}
} else {
System.err.println("Package has no certificates; ignoring!");
return null;
}
return list;
}
复制代码

4. java 设置多线程

复制代码
ist list = ListFile.readfile(filepath);
totalCount = list.size();
count = totalCount / threadNum;
for (int i = 0; i < 10; i++) {
PublicKeyParseThread parse = new PublicKeyParseThread();
parse.setBegin(i * count);
parse.setEnd((i + 1) * count - 1);
parse.setList(list);
Thread thread = new Thread(parse);
thread.start();
}
复制代码

5. db help

复制代码
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/", "root", "");
java.sql.Statement stmt = conn.createStatement();

String sql = "select aid from app_base_info where id > " + begin + " and id < " + end;
java.sql.ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getString("aid"));
list.add(rs.getString("aid"));
}
rs.close();
stmt.close();
conn.close();
复制代码






posted @   wtx  阅读(165)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示