• Post Reply Bookmark Topic Watch Topic
  • New Topic

iterateFiles method  RSS feed

 
Preethi Dev
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers!

Please someone give me your hand to solve this...i am in trial period in a company to get job on performance basis.

here is the thing!

i have to replace the manual uploading by copying the file and add into batch process where all the list of jobs run.

my idea!
1. copy the files from the directory from where it downloaded through FTP into new folder.

2. using the Iterator.iterateFiles() method in FileUtils class which iterate the files with the given extensions.

public static Iterator iterateFiles(File directory,
String[] extensions,
boolean recursive)

I am stuck at here --> how it works?
2. I am planning to use that returning file for file processing( validating, reformatting the files which is one of the process in our system)
3.then i need to update them in the database clob field.

this is my role that i have to play.

please someone guide me...


Thanks in advance
Preetha
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you like to iterate? You have (at least) two options:
- Breadth-first, meaning you first get all files in a folder, then the files of each sub folder, etc? Simply put, when a sub folder is encountered its contents are added to the end of the iteration.

- Depth first, meaning when a sub folder is found the iteration immediately follows its path instead of adding it to the end.

I've implemented both myself, and although I won't give you the full solution* these are the techniques I've used:

Breadth-first:
Each File found is put in a FIFO queue. The next() method removes the first element from this queue, returns it if it is not a folder. Otherwise the folder's children are added to the queue and the first element is removed again.

Depth-first:
Each File found is put in a queue. The next() method removes the first element from this queue, returns it if it is not a folder. Otherwise the folder's children are added at the start of the queue and the first element is removed again.


* the reasons:
1) we are NotACodeMill, we want you to DoYourOwnHomework
2) my code is GPL'ed so you wouldn't be allowed to use it in your application without making the application fall under the GPL as well. Your company won't like that.
 
Preethi Dev
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob!

got a great guidance...which i needed to tune my work. i was trying those two options which suits my application but got confused with the iterateFiles(). Now I am clear with it. I have done the updating CLOB field also.

Now i have the confident on doing this job.

Thanks again
Preetha

 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!