一个文件里面放置了图象,菜单等信息。进行读取,有兴趣的近来看看,有什么好的建议的望指点。
读取
String[] strings = AMBugs.getResource("\1\4\5\13\16\23\24\25\26\27\30\31\32\33\34\35\36\37");
片段代码如下:
protected static String[] getResource(String resourceNumbersString) throws
Exception {
byte flag = (byte) ( (theFlags >> 60) & 7);
if ( (flag >> 2 & 1) == 0) {
DataInputStream dis = null;
try {
int lastPos;
InputStream is = THEMidlet.getClass()
.getResourceAsStream("d.txt");
dis = new DataInputStream(is);
if (flag == 0) {
dis.skip(dis.readUnsignedShort() + 2);
flag = (byte) (dis.read() & 3);
if (flag == 3) {
theUIEncoding = dis.readUTF();
}
theFlags = theFlags | (long) flag << 60;
dis.close();
dis = null;
is = null;
String[] strings = getResource(resourceNumbersString);
return strings;
}
StringBuffer resourceNumbers = AMBugs.theStringBuffer;
resourceNumbers.delete(0, resourceNumbers.length())
.append(resourceNumbersString);
int stringsAmount = resourceNumbers.length();
int curResNumber = resourceNumbers.charAt(0);
int curAbsPos = (curResNumber + 1) * 2;
dis.skip(curAbsPos);
int curStringPos = dis.readUnsignedShort() + 4 + curAbsPos;
int nextStringPos;
curResNumber++;
lastPos = (resourceNumbers.charAt(stringsAmount - 1) + 1)
* 2 + 4;
int maxStringLength = 0;
int curStringLength;
int skip;
int i = 0;
stringsAmount = stringsAmount * 2 - 1;
while (true) {
resourceNumbers.insert(i++, (char) (curStringPos
- lastPos));
nextStringPos = dis.readUnsignedShort() + 4 +
(curResNumber + 1) * 2;
curResNumber++;
lastPos = nextStringPos;
curStringLength = nextStringPos - curStringPos;
maxStringLength = Math.max(maxStringLength, curStringLength);
resourceNumbers.setCharAt(i++, (char) curStringLength);
if (i < stringsAmount) {
skip = curResNumber;
curResNumber = resourceNumbers.charAt(i);
skip = (curResNumber - skip) * 2;
if (skip < 0) {
curStringPos = nextStringPos;
}
else {
if (skip > 0) {
dis.skip(skip);
}
curStringPos = dis.readUnsignedShort() + 4 +
(curResNumber + 1) * 2;
}
curResNumber++;
}
else {
break;
}
}
stringsAmount = resourceNumbers.length();
byte[] buf = new byte[maxStringLength];
String[] strings = new String[stringsAmount / 2];
for (i = 0; i < stringsAmount; i++) {
dis.skip(resourceNumbers.charAt(i++));
lastPos = resourceNumbers.charAt(i);
if (lastPos != 0) {
if (flag == 1) {
strings[i / 2] = dis.readUTF();
}
else {
dis.read(buf, 0, lastPos);
if (theUIEncoding == null) {
strings[i / 2] = new String(buf, 0, lastPos);
}
else {
strings[i / 2] = new String(buf, 0, lastPos,
theUIEncoding);
}
}
}
else {
strings[i / 2] = "";
}
}
return strings;
}
catch (Exception ignored) {
throw new Exception("Resource Bundle Exception");
}
finally {
try {
if (dis != null) {
dis.close();
}
}
catch (Throwable ignored) {}
}
}
else {
return null;
}
}
请教加交流,有兴趣的聊聊。
supcc@hotmail.com