Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About for loop of jdk1.5

 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags when you post source code.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it?
 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic