Results 1 to 5 of 5
- 11-22-2010, 10:34 PM #1
Member
- Join Date
- Nov 2010
- Location
- New Cross, London, UK
- Posts
- 18
- Rep Power
- 0
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(); }
- 11-23-2010, 10:20 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
And your problem is?
- 11-23-2010, 10:24 AM #3
Member
- Join Date
- Nov 2010
- Location
- New Cross, London, UK
- Posts
- 18
- Rep Power
- 0
- 11-23-2010, 10:45 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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.
- 11-23-2010, 10:47 AM #5
Member
- Join Date
- Nov 2010
- Location
- New Cross, London, UK
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
Saving and loading information
By applewood13 in forum New To JavaReplies: 1Last Post: 09-30-2010, 06:29 AM -
saving and loading information of a wizard on an XML file
By bulldo in forum EclipseReplies: 0Last Post: 08-02-2010, 11:26 AM -
reading input from array and saving output to database md5 algorithm
By avinash4m in forum Advanced JavaReplies: 4Last Post: 03-12-2009, 12:25 PM -
Loading jpegs into an array.
By mzatanoskas in forum New To JavaReplies: 3Last Post: 02-10-2009, 03:01 PM -
Saving data...?
By easyRyder in forum New To JavaReplies: 8Last Post: 07-15-2008, 04:14 AM
Bookmarks