Attempting to loop a text array while performing an action on each element

I am attempting to perform a file copy action upon each element in a string array. My current problem is how to execute the loop. I found the following somewhere but it doesn't even compile. Part of the problem, I am sure, is that 'file' is a String value and java.lang.string.* does not contain an Iterator method. So, how do I execute the loop?

dataDir = new File(context.getDataDirectory()); //I get the physical directory

String files[] = dataDir.list(); //I load the contents of the directory into an array

//Now I need to loop through each file in the directory and execute my copyToData method

for(Iterator iter = files.iterator(); iter.hasNext();)

{

String e = (String)iter.next();

// shell and/or vbscripts must be copied into the data directory of the channel

copyToData(context, e);

[852 byte] By [curtis_rowell@bmc.coma] at [2007-11-27 7:43:09]
# 1

public class Example {

public static void main(String[] args) {

String[] words = {"hello", "world", "how", "are", "you"};

for(String word : words) {

process(word);

}

}

static void process(String s) {

System.out.println(s);

}

}

Hippolytea at 2007-7-12 19:23:57 > top of Java-index,Java Essentials,New To Java...
# 2

I was able to get it to compile. What I was missing was adding the 'i' in 'String e = files;' The file array returns a string, but to get a single element out for each iteration through the loop, 'i' was needed. Now I can pass String e to my method.

dataDir = new File(context.getDataDirectory());

String files[] = dataDir.list();

for(i = 0; i < files.length;i++)

{

String e = files[i];

System.out.println("Current element in directory list array is: " + e);

context.log(26001,8,"Current element in directory list array is: " + e);

// shell and/or vbscripts must be copied into the data directory of the channel

copyToData(context, e);

}

curtis_rowell@bmc.coma at 2007-7-12 19:23:57 > top of Java-index,Java Essentials,New To Java...
# 3
When one doesn't need the loop index, I prefer the enhanced for loop (my example), but whatever works for you...
Hippolytea at 2007-7-12 19:23:57 > top of Java-index,Java Essentials,New To Java...
# 4
Your method requires 1.5. The platform I am coding for is using 1.4. Thanks for the info though, it looks much cleaner than the method I have to use.
curtis_rowell@bmc.coma at 2007-7-12 19:23:57 > top of Java-index,Java Essentials,New To Java...
# 5
> Your method requires 1.5. The platform I am coding for is using 1.4Ah, the other shoe drops.
Hippolytea at 2007-7-12 19:23:57 > top of Java-index,Java Essentials,New To Java...