How to Save ArrayLists?

Discussion in 'Plugin Development' started by PoseidonnodiesoP, Feb 22, 2014.

Thread Status:
Not open for further replies.
  1. I want to save a few ArrayLists so that I can log off and/or shut down the server and still have the data. How can I do this and then load them?
     
  2. Offline

    minecraft124_

    use the SLAPI to save/load the object.

    Code:java
    1. import java.io.FileInputStream;
    2. import java.io.FileOutputStream;
    3. import java.io.ObjectInputStream;
    4. import java.io.ObjectOutputStream;
    5.  
    6. /** SLAPI = Saving/Loading API
    7. * API for Saving and Loading Objects.
    8. * You can use this API in your projects, but please credit the original author of it.
    9. * @author Tomsik68<[email][email protected][/email]>
    10. */
    11. public class SLAPI
    12. {
    13. public static <T extends Object> void save(T obj,String path) throws Exception
    14. {
    15. oos.writeObject(obj);
    16. oos.flush();
    17. oos.close();
    18. }
    19. public static <T extends Object> T load(String path) throws Exception
    20. {
    21. T result = (T)ois.readObject();
    22. ois.close();
    23. return result;
    24. }
    25. }
     
Thread Status:
Not open for further replies.

Share This Page