⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java~40~

📁 一个好好的解包工具,它可以把打成资源包的文件用流的形式读出来并且可以把资源里的东东写到你指定的位置,资源可以使图片包和其他文件,很使用,愿意与大家一起分享
💻 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 {
      // 文件个数 4字节
      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字节
        b = new byte[1];
        dis.read(b);
        // 文件名 所占字节数等于刚刚所取出的长度值
        b = new byte[b[0]];
        dis.read(b);
        fileName[i] = byteToString(b);
        // 文件起始位置 4字节
        b = new byte[4];
        dis.read(b);
        fileStart[i] = byteToInt(b);
        // 文件长度 4字节
        b = new byte[4];
        dis.read(b);
        fileLength[i] = byteToInt(b);
      }
      dis.close();
      System.gc();
    } catch (Exception ex) {
    }
  }

  /**
   * byteToString 将字节数据转换成字符串
   *
   * @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 将字节数据转换成整数值
   *
   * @param b byte[]
   * @return int
   */
  private static int byteToInt(byte[] b) {
    // 如果字节长度不能构成一个整数则返回0
    if (b.length < 4) {
      return 0;
    }
    // 返回构成的整数
    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();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -