aspose file tools*
The moose likes Beginning Java and the fly likes About for loop of jdk1.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "About for loop of jdk1.5" Watch "About for loop of jdk1.5" New topic
Author

About for loop of jdk1.5

kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Hi all,

I have following code for copying files-



It's doing fine. But i am using jdk1.5, so i should use their utility.
Now i want to use for loop like
for(File file : listOfFiles ).
But using this i am unable think that how to take vaue of i for -
sourceStream = new FileInputStream("abc/" + listOfFiles[i].getName());
targetStream = new FileOutputStream("backupFolder/" + listOfFiles[i].getName());

Can you please help me?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3859

kayanaat sidiqui wrote:Now i want to use for loop like
for(File file : listOfFiles ).
But using this i am unable think that how to take vaue of i for -
sourceStream = new FileInputStream("abc/" + listOfFiles[i].getName());


I don't think you need the value of i but the element in the array index(which is referred by i). When you are using new for loop as you mentioned the "file" variable holds the current element of the array (i.e: listOfFiles). So you can directly use that to do what you want to do with it.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

Please use code tags when you post source code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Have you tried it?
kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Hi Campbell Ritchie/Jesper Young,

I tried the same but getting this error-
ERROR 2009-02-13 14:06:13,272 a.mine.backUpLogFile(SymProductProcessor.java:394) - Channel or stream is still in use, so cann't close..abc\2009-02-13_02-06-13\ abc\warn.log (The system cannot find the path specified)

the code i am using is as follows-


am i missing something?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

Please read this: How to use code tags.

I added code tags to your posts above. Next time please add them yourself.

Look carefully at what the error message says: The system cannot find the path specified

Does the target directory exist? Did you make a mistake by adding an extra space in the name? This looks suspicious:

abc\2009-02-13_02-06-13\ abc\warn.log

Note the space before the second "abc".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About for loop of jdk1.5