-
Problem with array Copy
Please check this:
Code:
String FOLDER_LIST[] = {"Test1", "Test2", "Test3", "Test4"};
for(int i = 0; i<FOLDER_LIST.length; i++){
tmp[][] = getFileCOntent(new File(drives["C:\\" + FOLDER_LIST + "\\"));
}
The above is supposed to go to all the 4 folders in the C:\ and copy the contents into a tmp array.. and then pass it to the final array..
The getFileCOntent() method takes in a File type, and gets all the files in the directory and stores and returns a 2D array to fill a jtable with the rows and columns..
The only problem i have is every time it does the loop, it wipes the contents of the files from the previous folders, only the last folder content is stored.. which is "Test4", how do I get the content of all the folders?
Thanks.
-
This line of code is your problem:
[code]
tmp[][] = getFileCOntent(new File(drives["C:\\" + FOLDER_LIST + "\\"));
[\code]
You reinitialize it each time, a very quick solution would be just to use a vector;
Code:
vector v;
v.add(what ever);
But if you have to use an array, try indexing the values of the array using the for loop variable int i! Indexing into the array will make sure that it doesn't keep getting rid of previous stuff.
i.e.