mercredi 29 avril 2015

How to create a new file in libgdx?

I am trying to create a new file into my game ( for saving purporses ) using Libgdx. I have no idea how to do this and all tutorials seem to write / read but not create the files.

try {

        //File file = new File("LnRSave.txt");
        FileHandle file = Gdx.files.local("LnRSave.txt");
        // if file doesnt exists, then create it
        if (!file.exists()) {

            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(jPoika.toJson(inventory));
        bw.close();

        System.out.println("Done");

    } catch (IOException e) {
        e.printStackTrace();
    }

Aucun commentaire:

Enregistrer un commentaire