• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

files are not beened deleted and renamed

 
Ranch Hand
Posts: 77
Android MyEclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 179
Mac Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MyEclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yashu23

Please check your private messages. Thanks.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some suggestions to improve/simplify your code:

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


Use


instead of

 
reply
    Bookmark Topic Watch Topic
  • New Topic