Jump to content

Java: File object not deleting

Featured Replies

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

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");

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.