Guest User

Untitled

a guest
Jul 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. package org.opendoorgames.test;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.files.FileHandle;
  5. import com.badlogic.gdx.utils.Json;
  6.  
  7. public class JsonFile {
  8.     static Json json = new Json();
  9.     static String external = "Saved Games/Collab-0/";
  10.     String folder;
  11.  
  12.     FileHandle dir;
  13.     FileHandle file;
  14.  
  15.     public JsonFile(String folder, String filename) {
  16.         dir = Gdx.files.external(external + folder);
  17.         if (!dir.exists())
  18.             dir.mkdirs();
  19.  
  20.         file = dir.child(filename);
  21.     }
  22.  
  23.     public <T> T read(Class<T> object) {
  24.         return json.fromJson(object, file);
  25.     }
  26.  
  27.     public <T> void write(T object) {
  28.         json.toJson(object, file);
  29.     }
  30. }
Add Comment
Please, Sign In to add comment