Reading Rar Files From Inside Java.

Okay so I have a project and I wish to like read images through a RAR file. Here’s my current loader:

public static URL osBG = jfrOS1.class.getResource("/An64/AA4/AnSYSUtils/AnOSBG.png");

Is there anyway I can pack part of that into a rar file, and have java read the “AnOSBG.png” that is inside the Rar file?

Any help would be great:)

I don’t know why you need to package them into rar files. You can instead embed them in your jar file itself. If you still need to, there is an opensource library called [icode]JUnRAR[/icode]

There is a limitation though, the rar files should be on the filesystem. A sample code would be


import com.github.junrar.*;

// Open an archive
Archive myRAR = new Archive(new File("myRAR.rar"));

// Get all the files
List<FileHeader> files = myRAR.getFileHeaders();

// The input stream of the file
InputStream ins;

// Iterate and get the file with your name
for (FileHeader hd : files)
{
    if (hd.getFileNameW().equals("myfileinrar"))
    {
        ins = myRAR.getInputStream(hd);
        break;
    }
}

I didn’t try this but this is my assumption that this will work by seeing the source. Hope this works.

Well I planned to keep my project Open Source at one point, and thought I’d make the res folders uneditable so they can change the code but not the looks.

If you’re going to distribute the game at all then it is going to be more trouble than it’s worth to try to keep people from changing the looks. My suggestion is to just not worry about keeping people from “modding” your game, and actually make the game :slight_smile: