I m trying to move file from one dir to another by using “PSUtilities.file:moveFile” . But because of threading for the file in windows i m not able to move file in one attempt.please suggest any option to solve this problem…!!!
Please be more specific. What error are you running into?
Basically, i m trying to move one excel file from one folder to another using java service ,and before moving i m retriving data from file and passing it to database, and for moving the file i m using move file service from psutils. after calculation move file service takes 3-4 attempts to move file , so repeated data is going in database, i need that file should move in one attempt.please have alook on the issue,waiting for u r reply
Is the moveFile service returning an error? If so, what is it?
I guess I’m not understanding why it’s taking 3-4 attempts to move the file. Something is up.
In any case, here are a couple of suggestions:
- Instead of processing the data first, then moving the file, do the opposite. Move the file. If the move was successful, then process the data. This should prevent duplicating the data in the database.
- Better yet! Consider using a File Polling port. The IS will take care of the file moves for you.
I m able to copy the file but not move.
what error do you get while executing moveFile
There is no error coming,
scenario is as follow
- I m reading excel file using java service
2)after fetching file, data is passing to the database
- and moving file from one deirectory to another
- I need that file should move by "moveFile " service.
- “moveFile” working fine for a file which i not implemented before by any service. In this case i m implementing excel file by “excelDocumentTo Record” java service, so i m not able to move file in one attempt.
6)and if i run directly it never move, only if i trace or step run its moving after 3-4 attempts.
I m thinking that some tread is used by the service which reading file, and it never releasing that. can u suggest me any option so that i can solve this issue.
I’m not familiar with this “excelDocumentToRecord” service, but I’m thinking you’re going to have to debug it. It sounds like it may not be closing the file appropriately.
As Percio suggested earlier, you should move the file first, as step one, not as step 3.
- Detect presence of new file.
- Move it to the target directory.
- Open the file.
- Process it to write data to the DB.
- Close the file.
Also as Percio pointed out, the file polling port can be used to great effect to help you do your processing. You can focus on the excelDocumentToRecord aspects and leave all the file management to the polling port facilities.
If you still havent got it resolved then here it is , if “excelDocumentTo Record” is a custom java service then check for closing the file stream after reading it as Percio suggested. I ran into the similar problem and while debugging came to know that it was not able to move the file because the file is being used by another program in this case it is our java program which when openned the file stream doesnt close the stream for sometime. Just used a .close method and everything went fine.
Hope this helps.