Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

files are not beened deleted and renamed

 
damodar kumar
Ranch Hand
Posts: 77
Android Chrome MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

mine aim is path contains a.txt it have to renamed to a_1.txt and have to delete the a.txt and a_1.txt have to rename to a.txt bt happening is

1) if that path contains a.txt

2) it is named to a_1.txt

3) its not deleting the a.txt and a_1.txt is not renamed to a.txt.

please suggest me by checking the above code.

Thanks

Damodar

[ June 16, 2008: Message edited by: damodar kumar ]
[ June 16, 2008: Message edited by: damodar kumar ]
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you edit your post (click on the paper and pencil icon) and put your code into code tags. This will make it much easier to read.
It's difficult to read your code but the only code i could see that you might be using to delete a file is a call to deleteOnExit. This will not delete the file until you exit the JVM (i.e. your program finishes). Try using the delete method instead and see if that fixes your problem.
 
Ravikanth kolli
Ranch Hand
Posts: 179
Chrome Eclipse IDE Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think deleteOnExit works since the file is deleted only during the virtual machine termination.

More information can be found here

you can try something like delete.

file is not renamed because a file with the same name already exists.
[ June 16, 2008: Message edited by: Ravikanth kolli ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently, this is continued from here. Damodar, in general it's better to continue a topic in the same thread you started in, if you're really just continuing the exact same discussion. That way people have access to all the earlier info and don't waste time saying things that have already been said before. Thanks.
 
damodar kumar
Ranch Hand
Posts: 77
Android Chrome MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jim Yingst

may be this come under same thread, but i got some different answer, which i not got with previous thread. there was no time wasting as i not mentioned, that please refer previous thread for more information , i mentined every thing clearly in the present thread.Also the code what i metioned before is different with the previous thread.
 
Yashpal Rawat
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I have some suggestions/queries

1. Is this a standalone program? If yes then deleteOnExit should work since
your jvm will exit once you are done with your program.
2. If you intend to only renmae the file then why you are not using only
renameTo method in File Class.
3. I think variable newname should be reset in each iteration
4. Also its not clear what is to be done in case directory have all files
already renamed.

I have modified your code below with assumption that if both old and new file you wanted to create already exists then new file will be over-written.

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yashu23

Please check your private messages. Thanks.
 
Vilmantas Baranauskas
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some suggestions to improve/simplify your code:

Use fileslist[i].endsWith(".pdf") instead of


Use


instead of

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic