saving an array to a file

ok i have this game that has a muti demental array for each map the maps are not vary big to all to geather it has about 800 values. is there an esay way to save all 800 values to a txt file, if so how?

thx cloudncali

Comments

  • : ok i have this game that has a muti demental array for each map the maps are not vary big to all to geather it has about 800 values. is there an esay way to save all 800 values to a txt file, if so how?
    :
    : thx cloudncali
    :
    I don't know how to save to files yet, but the most logical solution is to save them as strings, where each number in each row is separated by a space, and the rows are separated by line endings. This gives a text file, which looks like this:
    [code]
    1 2 3 4 5
    6 7 8 9 10 11
    12 13 14 15
    16 17 18 19 20
    [/code]
    Perhaps a predefined java class already has a save/load method for this, otherwise it is simple enough to write one.
  • : ok i have this game that has a muti demental array for each map the maps are not vary big to all to geather it has about 800 values. is there an esay way to save all 800 values to a txt file, if so how?
    :
    : thx cloudncali
    :

    you can use serialization to save an object as a file,
    the class of your object need to implement Serializable.
    to save an object:

    obj - your object
    try
    {
    ObjectOutputStream os=new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
    os.writeObject(obj);
    os.close();
    }
    catch(Exception e)
    {}

    to load an object from your file:

    try
    {
    ObjectInputStream is = new ObjectInputStream(new FileInputStream(file));
    return is.readObject();
    }
    catch(Exception e){}

    create a class that implement Serializable and containing your array,
    then you can save/load it as a file.
    or, you can try directly save your array(i am not sure this will work).

    my english sux
  • : : ok i have this game that has a muti demental array for each map the maps are not vary big to all to geather it has about 800 values. is there an esay way to save all 800 values to a txt file, if so how?
    : :
    : : thx cloudncali
    : :
    :
    : you can use serialization to save an object as a file,
    : the class of your object need to implement Serializable.
    : to save an object:
    :
    : obj - your object
    : try
    : {
    : ObjectOutputStream os=new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
    : os.writeObject(obj);
    : os.close();
    : }
    : catch(Exception e)
    : {}
    :
    : to load an object from your file:
    :
    : try
    : {
    : ObjectInputStream is = new ObjectInputStream(new FileInputStream(file));
    : return is.readObject();
    : }
    : catch(Exception e){}
    :
    : create a class that implement Serializable and containing your array,
    : then you can save/load it as a file.
    : or, you can try directly save your array(i am not sure this will work).
    :
    : my english sux
    :

    sorry for the "return", i copied from my program
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories