I am making a java game using path geometry. Is there any way to save the data stored in a Path2D to a file?
I have not tried any of these, but the following three solutions should work.
Save the input data
Instead of saving the Path2D object, save the values you have used to create the objects. As you said in the comments that you are creating the Path2D objects yourself using the API, you have the source data and you can control what to do with that.
If the first method sounds too complicated to fit to your application or you just prefer alternative solutions, Java's own serialization mechanism should do the trick. Path2D.Float and Path2D.Double implementations implement the Serializable interface, which means that they can be saved and loaded easily using ObjectOutputStream and ObjectInputStream. There are plenty of tutorials online if needed.
You can also use Shape.getPathIterator() to return an instance of PathIterator. This interface gives you the individual line and curve segments of the Path2D object, which you can save to a file. PathIterator and Path2D use the same types of segments, so this method should allow reconstructing the paths without losing any information. Note that while the getPathIterator() doesn't guarantee to return the exact same shape, checking the source code of Path2D seemed to return the internal model in their exact form. In contrast e.g. Ellipse2D can't be exactly represented with a PathIterator.