📄 packager.java
字号:
package com.eline.kjava.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
/**
* KJAVA的打包工具类。
* 比如读取jar文件信息来生成相应的jad文件
* @author Lucifer
*
*/
public class Packager {
/**
*
* @param jarFile
* @throws IOException
*/
public static String generanteJADFile(String jarFile) throws IOException {
Properties properties = new Properties();
JarFile jar = null;
try {
jar = new JarFile(jarFile);
Manifest man = jar.getManifest();
Attributes attrs = man.getMainAttributes();
Set set = attrs.entrySet();
Iterator i = set.iterator();
while (i.hasNext()) {
Object obj = i.next();
System.out.println(obj);
String[] keyValue = (String.valueOf(obj)).split("=");
if (keyValue.length == 2) {
String key = keyValue[0].trim();
String value = keyValue[1].trim();
properties.setProperty(key, value);
}
}
} catch (IOException e) {
throw e;
} finally {
if (jar != null)
jar.close();
}
int tmpPos = Math.max(jarFile.lastIndexOf('/'), jarFile.lastIndexOf('\\'));
String s1 = tmpPos > 0 ? jarFile.substring(tmpPos + 1) : jarFile;
System.out.println("s1 = " + s1);
properties.setProperty("MIDlet-Jar-URL", s1);
properties.setProperty("MIDlet-Jar-Size", String.valueOf(new File(jarFile).length()));
tmpPos = jarFile.lastIndexOf(".");
String s2 = (tmpPos > 0 ? jarFile.substring(0, tmpPos) : jarFile) + ".jad";
System.out.println("s2 = " + s2);
saveManifest(properties, new File(s2));
return s2;
}
// public static final String MANIFEST_CHARSET = "ISO-8859-1";
public static final String MANIFEST_CHARSET = "UTF-8";
/**
*
* @param props
* @param file
* @throws IOException
*/
public static void saveManifest(Properties props, File file) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(
new FileOutputStream(file),
MANIFEST_CHARSET);
Enumeration tmpKeys = props.keys();
while (tmpKeys.hasMoreElements()) {
String tmpKey = (String) tmpKeys.nextElement();
osw.write(tmpKey + ": " + props.get(tmpKey)+"\n");
}
osw.flush();
osw.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -