?? test.java~40~
字號:
import java.io.*;
import java.util.*;
public class Test {
public Test() {
try {
readResource();
for(int i=0;i<fileCount;i++)
{
System.out.println(fileName[i]);
byte [] b=this.getData(fileName[i]);
FileOutputStream fos=new FileOutputStream(new File("C:\\test\\"+fileName[i]));
fos.write(b);
fos.close();
}
} catch (Exception e) {
System.out.println("hew is ex " + e);
}
}
private static String[] fileName;
private static int[] fileStart;
private static int[] fileLength;
private static int fileCount;
private static String resource;
static InputStream is;
static DataInputStream dis;
public static void readResource() throws Exception {
is = new DataInputStream(new FileInputStream("D:/myproject/aoshifengsheng/aoshifsz_n7260/res/1.pak"));
dis = new DataInputStream(is);
byte[] b;
try {
// 文件個數(shù) 4字節(jié)
b = new byte[4];
dis.read(b);
fileCount = byteToInt(b);
fileName = new String[fileCount];
fileStart = new int[fileCount];
fileLength = new int[fileCount];
for (int i = 0; i < fileCount; i++) {
// 文件名長度 1字節(jié)
b = new byte[1];
dis.read(b);
// 文件名 所占字節(jié)數(shù)等于剛剛所取出的長度值
b = new byte[b[0]];
dis.read(b);
fileName[i] = byteToString(b);
// 文件起始位置 4字節(jié)
b = new byte[4];
dis.read(b);
fileStart[i] = byteToInt(b);
// 文件長度 4字節(jié)
b = new byte[4];
dis.read(b);
fileLength[i] = byteToInt(b);
}
dis.close();
System.gc();
} catch (Exception ex) {
}
}
/**
* byteToString 將字節(jié)數(shù)據(jù)轉(zhuǎn)換成字符串
*
* @param b byte[]
* @return String
*/
private static String byteToString(byte[] b) {
String str = "";
for (int i = 0; i < b.length; i++) {
str += (char) b[i];
}
return str;
}
public byte[] getData(String str) {
for (int i = 0; i < fileCount; i++) {
if (str.compareTo(fileName[i]) == 0) {
try {
dis = new DataInputStream(new FileInputStream("D:/myproject/aoshifengsheng/aoshifsz_n7260/res/1.pak"));
} catch (FileNotFoundException ex1) {
}
byte[] b = new byte[fileLength[i]];
try {
dis.skip(fileStart[i]);
dis.read(b);
dis.close();
return b;
} catch (IOException ex) {
ex.printStackTrace();
}
//if(fileName[i].){}
}
}
return null;
}
/**
* byteToInt 將字節(jié)數(shù)據(jù)轉(zhuǎn)換成整數(shù)值
*
* @param b byte[]
* @return int
*/
private static int byteToInt(byte[] b) {
// 如果字節(jié)長度不能構(gòu)成一個整數(shù)則返回0
if (b.length < 4) {
return 0;
}
// 返回構(gòu)成的整數(shù)
return ( (b[3] << 24) & 0xFFFFFFFF) | ( (b[2] << 16) & 0xFFFFFF) |
( (b[1] << 8) & 0xFFFF) | (b[0] & 0xFF);
}
public static void main(String args[]) {
Test test = new Test();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -