-1

如何遍历 jar 内文件夹中的资源?

我想做 Image.createImage(name) 很多次,所以我只需要名称列表。我需要使用 (FileConnection)Connector.open 吗?如果没有 root 访问权限,我就无法做到这一点,没有这个,我怎么知道我的应用程序在终端机器中的路径?

该解决方案提出了 ClassLoader,它不在 j2me 中,并且不再被回答: (J2ME) How to get list of files/resources inside my jar app

提前致谢!

4

1 回答 1

0

嗯,我不明白巴维克的意思。我找到了一种解决方法,使用 png 图像的名称创建一个 txt 文件。不过,我仍然不知道如何遍历 jar 中的 res 文件夹:

  InputStream is = getClass().getResourceAsStream("/Aves/dir.txt");
  int ch, isp=0;
  String l = "";
  do {
    ch = is.read();
    if ((ch != 13) && (ch != 10)) {
      l+=(char)ch;
    } else {
      if (ch == 13) {
        Image Img1 = Image.createImage("/Aves/"+l);
        sppW[isp] = Img1.getWidth();
        sppH[isp] = Img1.getHeight();
        Img1.getRGB(sppImg[isp], 0, Img1.getWidth(), 0, 0, Img1.getWidth(), Img1.getHeight());
        isp++;
        l = "";
      }
    }
  } while (ch != -1);
于 2012-12-16T21:33:27.637 回答