0

I have started getting into game programming.

My question is, that when I am working with files, either parsing data, writing to files, etc. Should I be using relative path names, or absolute pathnames, or something else which is better. I've heard about using jar files, but I am not sure

1. how that works

2. if it is a good way to do it.

So when developing a game that will be cross platform, what is the best method for managing files that the program will need to read from and write to.

anshulkatta
  • 2,044
  • 22
  • 30
user2444217
  • 581
  • 2
  • 7
  • 16

2 Answers2

0

The jar file is a zip of all your compiled *.class files and your resources. You can safely load your resources and even default data FROM a jar if you package your program, but you can NOT safely write data back to the jar. This detail is answered in depth already at

How can an app use files inside the JAR for read and write?

For information on how to package a jar see

http://docs.oracle.com/javase/tutorial/deployment/jar/

Community
  • 1
  • 1
seronis
  • 36
  • 2
0

there are several ways in which you can ship your code as a product. the most common are

  • packaging everything in one executable jar file.
  • having a set of folders where you place all necessary resources.

minecraft, for example, is written in java and distributed as a single executable jar file that contains all necessary class files and resources. to run the game (assuming you have java installed) all you need to do is double-click the jar file.

read this short tutorial about how to add a main class to a jar file.

either way, always treat classes and resources in your code as if they're in your classpath. for example, if you have a my.properties file on the root of the source tree then load it by using 'my.properties'. if you put it under a 'conf' folder then use 'conf/my.properties'. i think it is the safest way not to get lost.

are you using maven?