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
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 3670

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
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

Please use code tags when you post source code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32624
    
    4
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
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

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: jrebel
 
subject: About for loop of jdk1.5
 
Similar Threads
File.renameTo() Failing On Solaris
Merging byte arrays using SequenceInputStream
File sepearator for unix/windows problem
zip / pipedinputstream / pipedoutputstream problem
Transformation Problem For Arabic/French Character : HTML to XML