Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (472)
Games in Android Showcase (105)
games submitted by our members
Games in WIP (524)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  No matter what, it won't delete  (Read 1736 times)
0 Members and 1 Guest are viewing this topic.
Offline ReBirth
« Posted 2012-11-19 14:51:17 »

Seems File#delete() on Java 6 kinda fails (or not robust). Many people experienced this. Suggestions over internet that I have tried,
  • Call System.gc() before deletion
  • Close all stream, buffered, or what
  • check if it's exists, writeable, and delete() return true. Unfortunately they're all true.
Cool

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 729
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2012-11-19 14:53:31 »

do this:
1  
new FileOutputStream(theFileToDelete).close();

and it will throw an exception describing the problem.

Please note that if it works fine, the file is truncated (length = zero), which shouldn't be a problem, as you were about to delete it anyway.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ReBirth
« Reply #2 - Posted 2012-11-19 14:58:40 »

Nope, nothing thrown.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 334
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2012-11-19 15:12:28 »

I bet you're trying to delete something in the /bin folder in an Eclipse project, and Eclipse quickly scurries off and copies the corresponding file back from /src. Well, maybe. Otherwise I've found deletion to work perfectly fine since the dawn of time.

Cas Smiley

Offline ReBirth
« Reply #4 - Posted 2012-11-19 15:15:03 »

You lose the bet Smiley I tried to delete files inside a directory at user.home. The directory is created by this same program. Since I use System#getProperty, I believe I'm using absolute path.

My trolling mind tells me to go for native dll library just to delete.

Offline sproingie

JGO Kernel


Medals: 201



« Reply #5 - Posted 2012-11-19 17:24:13 »

In windows?  If you created it in user.home, the indexer might have it open.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 729
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2012-11-19 17:42:13 »

Can you delete the file manually?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Cero
« Reply #7 - Posted 2012-11-19 18:14:06 »

In windows?  If you created it in user.home, the indexer might have it open.

delete shouldnt return true in any case in which it isnt actually deleted


maybe you recreate the file yourself automatically ? Grin

Offline ReBirth
« Reply #8 - Posted 2012-11-20 03:10:11 »

Can you delete the file manually?
Flawlessly, straight to recycle bin Wink
maybe you recreate the file yourself automatically ? Grin
Grin I'll whack my program hardly if it creates new one right after I call my delete method. "I never taught you that!".

I haven't tried Java 7 yet, but some folks out there say it's fixed with it. Oh yeah this also only happens on Win 7 as far I read.

Online Agro
« Reply #9 - Posted 2012-11-20 03:50:05 »

Some guy online posted this and apparently it works:

Quote
in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
        System.gc();

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 334
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2012-11-20 09:32:45 »

That code is just voodoo nonsense.

Cas Smiley

Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2012-11-20 09:45:17 »

Have you tried writing a small test case that only deletes that file?

Offline Roquen
« Reply #12 - Posted 2012-11-20 12:00:09 »

As an aside to the issue: it sounds like you could be creating a temp file, if so...why not use the API for that.
Offline ReBirth
« Reply #13 - Posted 2012-11-20 12:15:53 »

Have you tried writing a small test case that only deletes that file?
Not yet, too lazy.

As an aside to the issue: it sounds like you could be creating a temp file, if so...why not use the API for that.
You mean File#createTempFile? it adds some magic numbers right after my file's name Cranky

Offline Roquen
« Reply #14 - Posted 2012-11-20 13:32:49 »

...and coupled with deleteOnExit and proper termination?
Offline ReBirth
« Reply #15 - Posted 2012-11-20 13:40:12 »

I haven't tried deleteOnExit yet but it maybe work. Proper termination? I always use System.exit(0) with some of my closing methods (saving data, release everything that has close(), dispose(), cleanup() etc).

Offline krasse
« Reply #16 - Posted 2012-11-20 14:07:47 »

Does it work to delete a file in another folder such as "C:\ReBirthTest"?

Offline ReBirth
« Reply #17 - Posted 2012-11-20 14:58:41 »

Yes. Does this have something to do with administrator thing?

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 729
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #18 - Posted 2012-11-20 14:59:58 »

Have you tried writing a small test case that only deletes that file?
Not yet, too lazy.
Do this. Otherwise you're just wasting everybodies time. persecutioncomplex

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ReBirth
« Reply #19 - Posted 2012-11-20 15:19:24 »

Do this. Otherwise you're just wasting everybodies time. persecutioncomplex
Aye captain!

...

Holy nut! they did! Shocked

Offline krasse
« Reply #20 - Posted 2012-11-20 15:58:01 »

Yes. Does this have something to do with administrator thing?
I had some issues way back with trying to modify files in windows-managed dirs, but it was a couple of years ago (on Vista). I can't seem to find the info I used back then though... It had something to do with that some files are not what they seem. They are actually located somewhere else and managed by windows so that you can get inconsistencies. I might be very wrong though since I can't find the info about it now.

Offline sproingie

JGO Kernel


Medals: 201



« Reply #21 - Posted 2012-11-20 18:08:28 »

Unless user.home is set to something really strange, it seems unlikely you'd run into folder virtualization problems, since the user home folder is where virtualization redirects to.  Usually it only bites you if you try writing to %ProgramFiles%

Offline ReBirth
« Reply #22 - Posted 2012-11-21 08:30:18 »

Thanks for all replies. I can just give up user.home and use other path.

Offline Best Username Ever

Junior Member





« Reply #23 - Posted 2012-11-21 19:26:26 »


Put a breakpoint on the line calling delete(). Then see if it allows you to delete the file while the program is paused. You may also want to try renaming/moving your file.

As an aside to the issue: it sounds like you could be creating a temp file, if so...why not use the API for that.
You mean File#createTempFile? it adds some magic numbers right after my file's name Cranky

What's wrong with that? (They're not magic numbers either. They're more like a UID.)

Thanks for all replies. I can just give up user.home and use other path.

Don't do that. Unless the user explicitly specifies their own path, then just treat every folder that's not the temporary file directory or under the user's home folder as if they were read only. If the other path works (on your computer), you're probably just sweeping a real problem under the rug.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #24 - Posted 2012-11-22 00:44:16 »

I've been hit by this problem before a few times and it always turned out to be my own fault, usually caused by creating a stream an not reliably closing it.
If you have to call System.gc() to make it work, than that's a sure sign you're doing something wrong (at least for me that was always the case).

Could you post the code that created the file, and the code that deletes the file?

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (20 views)
2014-07-10 20:20:18

CopyableCougar4 (21 views)
2014-07-10 02:26:14

CopyableCougar4 (28 views)
2014-07-09 02:55:38

Code Mage (28 views)
2014-07-08 23:57:00

Code Mage (15 views)
2014-07-08 23:49:08

AppleSauce (24 views)
2014-07-08 19:25:32

CopyableCougar4 (24 views)
2014-07-06 01:51:26

ipe369 (29 views)
2014-07-05 14:18:25

vastrolorde (40 views)
2014-07-04 18:45:44

theagentd (58 views)
2014-07-02 22:19:37
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!