0

I am asking for a Java code.

An ERP generates XML files in a folder, and each one has a different name.

For data extraction, I need to:

If new file is generated:

  1. Copy file from the main folder to a secondary folder

  2. Rename this file under "temp"

  3. Extract data with an ETL (Talend) from "temp"

  4. Delete the file "temp"

My question is: How to capture automaticaly a file with Java in order to copy or rename it each time one is generated?

Thanks

Mikahel
  • 81
  • 1
  • 15
  • I answered [something similar a while ago](http://stackoverflow.com/a/16251508/2071828) - watching for changes in a directory. Does that help at all? – Boris the Spider May 05 '14 at 13:44
  • Exactly, I need is a watchservice that monitor the addition of new files in the folder. How can I get the name of the new added files? Through the Watch Key? – Mikahel May 05 '14 at 15:28

2 Answers2

0

Your going to have to run a watch service with an infinite loop to keep checking if the folder has changed

theres a better explanation on how to do that here

after the change has triggered write a function to copy, rename and paste the file into your new "temp" folder. you can do this using filereader & filewriter.

user1768940
  • 14
  • 1
  • 3
  • So what I need is a watchservice that monitor the addition of new files in the folder, that's it? How can I get the name of the files, through the Watch Key? – Mikahel May 05 '14 at 15:26
  • @Mikahel Maybe read the [Javadoc for `Path`](http://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html)? – Boris the Spider May 05 '14 at 15:34
  • The Watchservice worked perfectly on my PC. The problem, it needs Java 7, and the company is still running on Java 6, so no java.nio library ... Another solution comparable to watchservice? – Mikahel May 08 '14 at 01:21
-1

Make a Job that runs every x minutes and check only files modified/created in the last x minutes.

cbach
  • 394
  • 3
  • 8