Results 1 to 5 of 5
  1. #1
    blazecode is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Question Can't Delete A File

    I used the following codes but i am unable to delete the file. Can anyone help ??

    import java.io.File;



    public class Delete {

    public static void main(String[] args) {

    Thread a = new Thread();

    a.start();



    }

    public void run()

    {
    String fileName = "default\\sample.txt";

    // A File object to represent the filename

    File f = new File(fileName);



    // Make sure the file or directory exists and isn't write protected

    if (!f.exists())

    throw new IllegalArgumentException(

    "Delete: no such file or directory: " + fileName);



    if (!f.canWrite())

    throw new IllegalArgumentException("Delete: write protected: "

    + fileName);



    // If it is a directory, make sure it is empty

    if (f.isDirectory()) {

    String[] files = f.list();

    if (files.length > 0)

    throw new IllegalArgumentException(

    "Delete: directory not empty: " + fileName);

    }

    // Attempt to delete it

    f.delete();

    }



    }



    Or is there any other way to delete a file using threads ???

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Have you had any exceptions, when you run this code?
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    blazecode is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default Solved

    I just need to extend the class to Threads and change the codes as

    public class Delete extends Threads

    then

    Thread a= new Delete();

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    So Did you solve this task?
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    blazecode is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

Similar Threads

  1. i want to read xml file from ftpserver and after i also want to delete from ftp
    By enggvijaysingh@gmail.com in forum Advanced Java
    Replies: 1
    Last Post: 11-20-2010, 08:05 PM
  2. Delete A File
    By nitinverma in forum CLDC and MIDP
    Replies: 13
    Last Post: 06-15-2010, 09:12 AM
  3. Delete From .txt file
    By Sarinam in forum New To Java
    Replies: 86
    Last Post: 06-28-2008, 11:17 AM
  4. problem when I try to delete a file
    By tommy in forum Advanced Java
    Replies: 2
    Last Post: 07-31-2007, 03:44 PM
  5. How to delete a file
    By Alpha in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 09:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •