Question

I am writing a game in java, and i would like to save my game. I am going to save it as a set of XML documents in a zip file. What i would like to know is if their is a way i can do this transparently so that the user cannot edit these files, or find them. I have thought about just making the files hidden, but that seems like a dirty and ugly way to do this. The thing i like least about the hidden files is that they don't seem compatible between systems. If their was anyway to save the files to the jar and read them from it that would also be equally as acceptable. Also there doesn't seem like a good way in java to make a file hidden. Any help would be greatly appreciated.

Was it helpful?

Solution

What i would like to know is if their is a way i can do this transparently so that the user cannot edit these files, or find them.

Ultimately, no.

Anything that you do to store state on the local machine can ultimately be reverse engineered and that state can be retrieved by a privileged user.

But there are various things you could do to make it difficult for people to "cheat". For instance, you could encrypt the file, or generate a seeded hash to detect "tinkering".


Hiding files on Java 7 is simple:

Path path = FileSystems.getDefault().getPath("directory", "hidden.txt");
Boolean hidden = path.getAttribute("dos:hidden", LinkOption.NOFOLLOW_LINKS);
if (hidden != null && !hidden) {
    path.setAttribute("dos:hidden", Boolean.TRUE, LinkOption.NOFOLLOW_LINKS);
}

(Copied from: http://javarevisited.blogspot.com/2012/01/how-to-hide-file-java-program-example.html)

On earlier versions of Java you needed to call an external Windows application or call a native library to do it. But note that:

  • "hidden" files are only hidden from users who don't bother to look
  • they work differently on different platforms; e.g. for Linux/Unix based systems, "hidden" just means that the filename starts with a ".".
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top