Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

copy and move methods are not working properly  RSS feed

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I tried a lot but not able to fix my following code:


my rename, copy and move file methods:


ERROR.MI.FileManager.java - moveFile()


ERROR.MI.FileManager.java - copyFile()


Please advise

Thanks in anticipation
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any advice please
 
Tony Docherty
Bartender
Posts: 3200
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception stack traces tell you what is wrong.

java.lang.NullPointerException
at FileManager.copyFile(FileManager.java:87)

Your move is failing because line 87 of FileManager is trying to dereference a null value ie it is trying to use a variable that contains null. I can't help further because I've no idea which line line 87 is.

java.io.FileNotFoundException: /home/bulkSavedCVs/5/30774Peter_original.doc (No such file or directory)

Copy is failing because the file (the full path is shown in the exception message) can't be found. Make sure your file is in that directory or make sure you are specifying the correct directory.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony for your reply. The error is self explanatory but I am looking for anybody to detect error from my code and to rectify it

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I analyzed and found that all the code is working fine but when file is renamed then moveFile() method is not working. I doubt the file resources became engaged and its unable to move. Am I right? If yes what should I do?

Thanks again
 
Tony Docherty
Bartender
Posts: 3200
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt the file resources became engaged and its unable to move. Am I right? If yes what should I do?

I don't even know what you mean by this, can you explain further.

If the file has been renamed (and assuming all file locks have been released) and you are trying to move the file using it's new name this should work. If you are trying to move the file using it's old name then clearly it won't be found.
Also if the file is open in another application and that application has locked the file then you won't be able to move it but if this was the case you wouldn't get a FileNotFoundException.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote: if the file is open in another application and that application has locked the file then you won't be able to move it but if this was the case you wouldn't get a FileNotFoundException.

When file is renamed then immediately my code is trying to move. Here I assume its locked by rename method. How can I release it and then move?

Thanks again
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for assisting me. I found the problem. My following moveFile method was running copy file method if it was unable to move and thereafter deleting the file that was causing the whole problem and fileNotFound or NPE was throwing:

I changed this to following code and now its working fine:


Thanks again & Best regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!