Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2010
    Location
    New Cross, London, UK
    Posts
    18
    Rep Power
    0

    Default Saving from, and loading to an array.

    Hi all, basically, I want to save data from an array to a file, and then be able to load it again. The data comes to the array from a tokenizer, so I want to put the data into the file after it has been passed to the array from the tokenizer.

    Thanks in advance.

    Java Code:
    public void stringTokenizer(String a)
        {
            //Creates variable for loop counter.
            int i;
            //Creates StringTokenizer object that takes 'a' parameter from method sig, and had deliminator ','.
            StringTokenizer tokenizer = new StringTokenizer(a, ",");
            //Creates notesTwo array with the amount of indexes defined by the value of tokenizer.countToken()
            notesTwo = new int[tokenizer.countTokens()];
            //Initializes 'i' to zero.
            i = 0;
            //While hasMoreTokens is true (when there are still parts of the string to process), the loop will run.
            //Integer converts each token to an int.
            while(tokenizer.hasMoreTokens())
            {
                //Creates Integer object with the input nextToken; nextToken feeds token to the integer function; hence it is Integer's parameter.
                //Each time the tokenizer is run, the string is essentially shortened as different tokens are processed.
                Integer intStore = new Integer(tokenizer.nextToken());
                //Stores the value of intStore(Integer Object) into the notesTwo Array. Array index is defined by i++
                notesTwo[i] = intStore.intValue();
                //Increments 'i' variable by one.
                i++;
            }
            
            //Refer to notes on populateArray. NOTE: uses second Array, and second payNote method. NOT initially coded Method.
            int wait;
            int runs;
            runs = 0;
            wait = 500;
            while(runs < 4)
            {
                playNoteTwo(0);
                    synth.wait(wait);
                playNoteTwo(1);
                    synth.wait(wait);
                playNoteTwo(2);
                    synth.wait(wait);
                playNoteTwo(3);
                    synth.wait(wait);
                runs++;
            }
            synth.stopSound();
        }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    And your problem is?

  3. #3
    Join Date
    Nov 2010
    Location
    New Cross, London, UK
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    And your problem is?
    I am not sure which class to use and how to implement it. I have been reading about the FileInputStream and FileOutputStream classes, but i'm not sure.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    What does your array consist of?
    Strings?
    Then FileWriter and FileReader.

    Or (and I think you can do this) simply serialise it out using an ObjectOutputStream, and read in using an ObjectInputStream. Assuming you don't care about the format of the data in the file.

  5. #5
    Join Date
    Nov 2010
    Location
    New Cross, London, UK
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    What does your array consist of?
    Strings?
    Then FileWriter and FileReader.

    Or (and I think you can do this) simply serialise it out using an ObjectOutputStream, and read in using an ObjectInputStream. Assuming you don't care about the format of the data in the file.
    Its ints. I'll have a look at ObjectOutputStream and ObjectInputStream. Cheers.

Similar Threads

  1. Saving and loading information
    By applewood13 in forum New To Java
    Replies: 1
    Last Post: 09-30-2010, 05:29 AM
  2. Replies: 0
    Last Post: 08-02-2010, 10:26 AM
  3. Replies: 4
    Last Post: 03-12-2009, 11:25 AM
  4. Loading jpegs into an array.
    By mzatanoskas in forum New To Java
    Replies: 3
    Last Post: 02-10-2009, 02:01 PM
  5. Saving data...?
    By easyRyder in forum New To Java
    Replies: 8
    Last Post: 07-15-2008, 03:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •