Results 1 to 2 of 2
  1. #1
    coco is offline Member
    Join Date
    Jul 2007
    Posts
    39
    Rep Power
    0

    Default Problem with array Copy

    Please check this:

    Java 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.

  2. #2
    toby is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    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;
    Java 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.

    Java Code:
    tmp[j] = value etc

Similar Threads

  1. array problem
    By oceansdepth in forum New To Java
    Replies: 3
    Last Post: 04-05-2008, 02:25 AM
  2. Array problem.. help needed please!
    By SCS17 in forum New To Java
    Replies: 3
    Last Post: 03-06-2008, 10:30 PM
  3. TextArea additable and uneditable (copy/past problem)
    By qwerty55 in forum Advanced Java
    Replies: 0
    Last Post: 01-19-2008, 11:41 PM
  4. array problem
    By wats in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 07:08 AM
  5. array problem
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 01:13 AM

Posting Permissions

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