Cant delete file on local harddrive
Hello,
I want to delete a file outside my application on the local harddrive but it doesnt work. This is my whole java file code:
package test;
import java.io.*;
publicclass Main{
public Main(){
}
publicstaticvoid main(String[] args){
String PathName ="C:\\Program Files\\test\\temp.mdb";
File tempFile =new File(PathName);
System.out.println(tempFile.getPath());
System.out.println(tempFile.exists());
System.out.println(tempFile.delete());
System.exit(0);
}
}
The wierd thing is that I get the following output:
C:\Program Files\test\temp.mdb
true
true
It says true and the file is still there! How can that be possible? I have no program running on it what I know of.
[1286 byte] By [
tolvana] at [2007-11-27 5:21:24]

> It says true and the file is still there! How can> that be possible? I have no program running on it> what I know> of.There is at least one you do not know of, yet.
> > It says true and the file is still there! How can> > that be possible? I have no program running on it> > what I know> > of.> > There is at least one you do not know of, yet.And how do I find out what program it
> ...> And how do I find out what program it is?Try this: http://www.microsoft.com/technet/sysinternals/Security/ProcessExplorer.mspx
It does seem a bit weird, given that delete() is documented to "true if and only if the file or directory is successfully deleted; false otherwise".
TrySystem.out.println(tempFile.exists());
System.out.println(tempFile.delete());
System.out.println(tempFile.exists());
and do a "dir" before and after. Post what you get.
[Edit] I'm happy to be proved wrong, but what I'm getting at is that maybe the file *is* being deleted. And it's your belief that it isn't that's faulty.
Didn't you resolve this a week ago?
> It does seem a bit weird, given that delete() is
> documented to "true if and only if the file or
> directory is successfully deleted; false otherwise".
>
> TrySystem.out.println(tempFile.exists());
> System.out.println(tempFile.delete());
> System.out.println(tempFile.exists());
and do a
> "dir" before and after. Post what you get.
>
> [Edit] I'm happy to be proved wrong, but what I'm
> getting at is that maybe the file *is* being deleted.
> And it's your belief that it isn't that's faulty.
I get:
true
true
true
> Didn't you resolve this a week ago?Nope, the problem is still unsolved.
> > Didn't you resolve this a week ago?> > Nope, the problem is still unsolved.:-( did you try System.gc()? Something must still have a handle to that file. It's an M$ Access db, right?
package test;
import java.io.*;
public class Main {
public Main() {
}
public static void main(String[] args) {
System.gc();
String PathName = "C:\\Program\\test\\temp.mdb";
File tempFile = new File(PathName);
System.out.println(tempFile.getPath());
System.out.println(tempFile.exists());
System.out.println(tempFile.delete());
System.out.println(tempFile.exists());
System.exit(0);
}
}
Returns:
C:\Program\test\temp.mdb
true
true
true
> > Didn't you resolve this a week ago?> > Nope, the problem is still unsolved.Did you try that process explorer from Microsoft I posted earlier to see if there is something holding (and perhaps restoring since delete() returns true) the database?
> > > Didn't you resolve this a week ago?
> >
> > Nope, the problem is still unsolved.
>
> Did you try that process explorer from Microsoft I
> posted earlier to see if there is something holding
> (and perhaps restoring since delete() returns
> true) the database?
I dont know how to use the program. Can you please guide me? I have downloaded and started the program.
> ...> I dont know how to use the program. Can you please> guide me? I have downloaded and started the program.Try the integrated help-pages or checkout the lower part of the download link titled: Microsoft Process Explorer KB Articles.
> > ...
> > I dont know how to use the program. Can you please
> > guide me? I have downloaded and started the
> program.
>
> Try the integrated help-pages or checkout the lower
> part of the download link titled: Microsoft
> Process Explorer KB Articles.
Cant find anything that helps me with this. I searched for the filename in the Process Explorer and it returned no results.
> > > Didn't you resolve this a week ago?
> >
> > Nope, the problem is still unsolved.
>
> :-( did you try System.gc()? Something must
> still have a handle to that file. It's an M$ Access
> db, right?
Yes I tried that. Yes it is an MS Access db.
> > > > Didn't you resolve this a week ago?
> > >
> > > Nope, the problem is still unsolved.
> >
> > :-( did you try System.gc()? Something must
> > still have a handle to that file. It's an M$
> Access
> > db, right?
>
> Yes I tried that. Yes it is an MS Access db.
Can you delete other files? What about other Access files? Create a new access file and try and delete it. Does that work?
> > > > > Didn't you resolve this a week ago?
> > > >
> > > > Nope, the problem is still unsolved.
> > >
> > > :-( did you try System.gc()? Something
> must
> > > still have a handle to that file. It's an M$
> > Access
> > > db, right?
> >
> > Yes I tried that. Yes it is an MS Access db.
>
> Can you delete other files? What about other Access
> files? Create a new access file and try and delete
> it. Does that work?
I can delete for an example a .txt file. I tried to create a new .mdb file but I cant delete that so it has to be something with .mdb. .doc doesnt work either.
I tried to do this on a machine with Windows XP. It worked! So it has to be something with Windows Vista. What can it be?
> > > > > > Didn't you resolve this a week ago?
> > > > >
> > > > > Nope, the problem is still unsolved.
> > > >
> > > > :-( did you try System.gc()? Something
> > must
> > > > still have a handle to that file. It's an M$
> > > Access
> > > > db, right?
> > >
> > > Yes I tried that. Yes it is an MS Access db.
> >
> > Can you delete other files? What about other
> Access
> > files? Create a new access file and try and delete
> > it. Does that work?
>
> I can delete for an example a .txt file. I tried to
> create a new .mdb file but I cant delete that so it
> has to be something with .mdb. .doc doesnt work
> either.
>
> I tried to do this on a machine with Windows XP. It
> worked! So it has to be something with Windows Vista.
> What can it be?
That Vista is a baby-sitting, hand-holding pile of ****, maybe? Perhaps something in the background is scanning or indexing files, and it has a hold of that file for too long
> > > > > > Didn't you resolve this a week ago?
> > > > >
> > > > > Nope, the problem is still unsolved.
> > > >
> > > > :-( did you try System.gc()? Something
> > must
> > > > still have a handle to that file. It's an M$
> > > Access
> > > > db, right?
> > >
> > > Yes I tried that. Yes it is an MS Access db.
> >
> > Can you delete other files? What about other
> Access
> > files? Create a new access file and try and delete
> > it. Does that work?
>
> I can delete for an example a .txt file. I tried to
> create a new .mdb file but I cant delete that so it
> has to be something with .mdb. .doc doesnt work
> either.
>
> I tried to do this on a machine with Windows XP. It
> worked! So it has to be something with Windows Vista.
> What can it be?
It is possible I suppose that this is a Vista security issue. The only bug I found that was even remotely related was http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6504236
It's not really the same at all except it does talk about the effects of Vista's integrity process rigamarole which may be the essence of your problem as well.
Do you have any other software like anti-virus software that may be interfering? If so turn it off.
If you can produce the problem with some regularity (and it would probably be swell if you could reproduce the problem on another computer also running Vista) then I would file a bug report with Sun.
Not that you'll get a fix anytime soon, mainly because it is a Vista bug more than anything but I don't know what else you can do and perhaps someone somewhere might come up with a solution.
I run the same program and it will delete file from that directory successfully. No problem in program.
> I run the same program and it will delete file from> that directory successfully. No problem in program.Do you use Windows Vista?
> > > > > > > Didn't you resolve this a week ago?
> > > > > >
> > > > > > Nope, the problem is still unsolved.
> > > > >
> > > > > :-( did you try System.gc()? Something
> > > must
> > > > > still have a handle to that file. It's an M$
> > > > Access
> > > > > db, right?
> > > >
> > > > Yes I tried that. Yes it is an MS Access db.
> > >
> > > Can you delete other files? What about other
> > Access
> > > files? Create a new access file and try and
> delete
> > > it. Does that work?
> >
> > I can delete for an example a .txt file. I tried
> to
> > create a new .mdb file but I cant delete that so
> it
> > has to be something with .mdb. .doc doesnt work
> > either.
> >
> > I tried to do this on a machine with Windows XP.
> It
> > worked! So it has to be something with Windows
> Vista.
> > What can it be?
>
> It is possible I suppose that this is a Vista
> security issue. The only bug I found that was even
> remotely related was
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=650
> 4236
>
> It's not really the same at all except it does talk
> about the effects of Vista's integrity process
> rigamarole which may be the essence of your problem
> as well.
>
> Do you have any other software like anti-virus
> software that may be interfering? If so turn it off.
>
>
> If you can produce the problem with some regularity
> (and it would probably be swell if you could
> reproduce the problem on another computer also
> running Vista) then I would file a bug report with
> Sun.
>
> Not that you'll get a fix anytime soon, mainly
> because it is a Vista bug more than anything but I
> don't know what else you can do and perhaps someone
> somewhere might come up with a solution.
Ok thank you for the answere. How do I report a bug to sun?
> > > > > > > Didn't you resolve this a week ago?
> > > > > >
> > > > > > Nope, the problem is still unsolved.
> > > > >
> > > > > :-( did you try System.gc()? Something
> > > must
> > > > > still have a handle to that file. It's an M$
> > > > Access
> > > > > db, right?
> > > >
> > > > Yes I tried that. Yes it is an MS Access db.
> > >
> > > Can you delete other files? What about other
> > Access
> > > files? Create a new access file and try and
> delete
> > > it. Does that work?
> >
> > I can delete for an example a .txt file. I tried
> to
> > create a new .mdb file but I cant delete that so
> it
> > has to be something with .mdb. .doc doesnt work
> > either.
> >
> > I tried to do this on a machine with Windows XP.
> It
> > worked! So it has to be something with Windows
> Vista.
> > What can it be?
>
> It is possible I suppose that this is a Vista
> security issue. The only bug I found that was even
> remotely related was
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=650
> 4236
>
> It's not really the same at all except it does talk
> about the effects of Vista's integrity process
> rigamarole which may be the essence of your problem
> as well.
>
> Do you have any other software like anti-virus
> software that may be interfering? If so turn it off.
>
>
> If you can produce the problem with some regularity
> (and it would probably be swell if you could
> reproduce the problem on another computer also
> running Vista) then I would file a bug report with
> Sun.
>
> Not that you'll get a fix anytime soon, mainly
> because it is a Vista bug more than anything but I
> don't know what else you can do and perhaps someone
> somewhere might come up with a solution.
My experience with Vista is that it does it's damnedest to stop you doing anything outside of the realms of the casual user. When I first got it ( it came installed on a laptop, I didn't ask for it, nor want it ) every time I opened anything I'd first have to give my express permission for it to happen. The included "firewall" got itself all confused, too, it tried to block something, but first I had to give it express permission to do so, which seemed so utterly counter-productive I had to have a bit of a sit down to recover (effectively "You do not have permission to prevent unauthorized access to your machine"). I bet it's one of these stupid measures that's keeping a handle on the file
>
> Ok thank you for the answere. How do I report a bug
> to sun?
http://bugs.sun.com/services/bugreport/index.jsp
But again I HIGHLY recommend that you provide as much information as possible like - creating new file and then trying to delete fails - that only some files have this problem - that this only happens on Vista .etc
If you want them to take you at all seriously.