Jump to content

Java: File object not deleting


Guest tkforever

Recommended Posts

Guest tkforever

This is what I've got basically and during run-time it's not working.

/****************************************/

File tk = new File(String path);

 

boolean delCheck = false

 

if(tk.exists())

delCheck = tk.delete();

 

if(delCheck)

System.out.println ("Delete Complete");

else

System.out.println ("The file was unable to be deleted");

/****************************************/

 

I've made sure my buffered reader objects are closed and all file threads are closed. The File exists at the location I'm sure, any suggestions? I must be missing something.

 

thanks

tk

Link to comment
Share on other sites

This is what I've got basically and during run-time it's not working.

/****************************************/

File tk = new File(String path);

 

boolean delCheck = false

 

if(tk.exists())

delCheck = tk.delete();

 

if(delCheck)

System.out.println ("Delete Complete");

else

System.out.println ("The file was unable to be deleted");

/****************************************/

 

I've made sure my buffered reader objects are closed and all file threads are closed. The File exists at the location I'm sure' date=' any suggestions? I must be missing something.

 

thanks

tk[/quote']

 

Assuming you made the java.io.File import at the beggining of that file,

why are you declaring a string here

File tk = new File(String path);

instead of passing it one?

Like

File tk = new File("/home/user/file.txt");

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.