Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append counter to string to loop through list

Status
Not open for further replies.

Wrathchild

Technical User
Aug 24, 2001
303
US
how would I loop through these items to run the check that they exist so I can use i after "App"? I'm just looking for the syntax for "App & i".

int i = 0;

File App0 = new File("C:\\test.txt");
File App1 = new File("C:\\test2.txt");

while
if(App & i.exists()){ blah blah blah

i++
 
Java is a compiled language, so you can't access variable names dinamically at runtime.

There is an approach to do this called reflection, but I don't think it's good for your case.

I'd store the File objects in a File array so you can loop throgh the array and check the existence of each element.

Cheers,

Dian
 
thanks, I was thinking that, but I didn't know if there was a File array or not
 
I'm not talking about a special class, you can declare an array of any kind of objects or primitive types-

Something like

Code:
File[] fileArray = new File[numberOfFiles];
for (i=0;i<fileArray.length;i++)
  if fileArray[i].exists()
     doWhatever();

Cheers,

Dian


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top