Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-24-2008, 05:19 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Deleting a File that is opened
I am reading a text file that is being used by some other process. I want to delete it after using. How this is possible.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-24-2008, 05:55 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 840
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Hope this helps.... Google is your friend.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-24-2008, 11:09 PM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Thanks but it only works if file is not being used. I have a Java thread that is writing to the text file. The second thread tries to delete the file. Is it possible?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-25-2008, 03:40 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 840
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by ravian View Post
Thanks but it only works if file is not being used. I have a Java thread that is writing to the text file. The second thread tries to delete the file. Is it possible?
Hmm.... it's my understanding that it might not be able to delete a file that is being used - that's just plain OS/Software fundamentals. Ever try deleting your Word or Open Office document that's currently open? You get a lovely popup message saying "you must close this file before you can delete it"... or something to that effect. But maybe there is a way in Java... maybe someone knows. What we do know, is that even though you have two threads, at some point the thread using the file will eventually stop using the file, unless you've implemented an infinite loop into the program.... interesting question nevertheless.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-26-2008, 07:11 PM
Member
 
Join Date: Jan 2008
Posts: 4
DwayneWayne is on a distinguished road
It is possible... I reckon that you save your loaded data from the file in some sort of data-structure, array etc.

You need to load the file and then remember to use the .close() method, then you should be able to overwrite/delete the file.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-26-2008, 09:36 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Try this
Hello DwayneWayne

You can try the File.deleteOnExit() method. It should wait until your program finishes running and then deletes the file. However, this will not work, if some other program is using the file.

Good luck!
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-30-2008, 03:05 PM
Member
 
Join Date: Jan 2008
Posts: 1
it2051229 is on a distinguished road
Yeah.. Can java do it?
Yeah.. i was also wondering if Java has the ability to stop a currently running process and then delete the file.. is that possible? if it is, how do i do it?? any work around tricks you have?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting All rows in the JTable surot New To Java 1 04-16-2008 11:44 AM
Reading an already opened file Java Tip Java Tips 0 01-25-2008 07:50 PM
deleting elements nalinda New To Java 2 12-06-2007 02:42 AM
Short key for getting list of opened classes in Eclipse Java Tip Java Tips 0 12-04-2007 12:11 PM
How to know the ports opened by JVM sandeepspatil Advanced Java 1 08-02-2007 02:51 PM


All times are GMT +3. The time now is 02:25 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org