Results 1 to 3 of 3
  1. #1
    tommy is offline Member
    Join Date
    Jul 2007
    Posts
    41
    Rep Power
    0

    Default problem when I try to delete a file

    I'm trying to delete a file but my code doesn't work, and I don't know the cause
    can you help me?

    Java Code:
    FileInputStream fins= new FileInputStream(mypath);
    BufferedReader brd = new BufferedReader(new InputStreamReader(fins));
    boolean bsr=fins.delete();
    if(bsr.equals("true"))
    {
    out.println("file deleted");
    }
    else
    out.println("file not deleted");

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Not sure why you are using the FileInputStream.
    Try this
    Java Code:
    File file = new File(mypath);
    file.delete();

  3. #3
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Also because bsr is a boolean you can just check it like this
    Java Code:
    if (bsr == true)
    //or
    if (bsr)

Similar Threads

  1. [SOLVED] Delete Current line from file
    By Azndaddy in forum New To Java
    Replies: 2
    Last Post: 04-06-2012, 08:00 AM
  2. Listbox Add/Delete
    By Rageagainst20 in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 04:49 PM
  3. Replies: 0
    Last Post: 04-05-2008, 10:13 AM
  4. problem with jar file pls help
    By jinu5 in forum New To Java
    Replies: 0
    Last Post: 08-15-2007, 10:41 PM
  5. How to delete a file
    By Alpha in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 08:11 AM

Posting Permissions

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