Results 1 to 5 of 5
  1. #1
    reeveliew is offline Member
    Join Date
    May 2010
    Posts
    13
    Rep Power
    0

    Default help~ delete method cant work

    import javax.swing.*;
    import java.io.File;

    public class Third {

    public static void main(String[] args) throws Exception {
    String humanName; // A local variable to hold the name.

    humanName = JOptionPane.showInputDialog(null, "Enter the file name");
    File file = new File((+ humanName)".txt");
    System.out.println(file.delete());
    JOptionPane.showMessageDialog(null, "File deleted" + humanName);




    }

    }



    how to fix ><

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,445
    Rep Power
    18

    Default

    Post code in CODE tags, and make sure it's formatted code.
    What does "can't work" mean?
    Errors?
    Exceptions?
    What?

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by reeveliew View Post
    File file = new File((+ humanName)".txt");
    how to fix ><

    the code above is illegal. fix it with

    Java Code:
    File file = new File(humanName + ".txt");
    you should also specify the path.

  4. #4
    reeveliew is offline Member
    Join Date
    May 2010
    Posts
    13
    Rep Power
    0

    Default

    thx dude, solved

  5. #5
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    Quote Originally Posted by reeveliew View Post
    import javax.swing.*;
    import java.io.File;

    public class Third {

    public static void main(String[] args) throws Exception {
    String humanName; // A local variable to hold the name.

    humanName = JOptionPane.showInputDialog(null, "Enter the file name");
    File file = new File((+ humanName)".txt");
    System.out.println(file.delete());
    JOptionPane.showMessageDialog(null, "File deleted" + humanName);




    }

    }



    how to fix ><
    just curious...didnt the compiler complain on that?

Similar Threads

  1. why doesnt my insertion sort method not work?
    By Jeremy8 in forum New To Java
    Replies: 7
    Last Post: 11-15-2009, 02:56 AM
  2. Replies: 2
    Last Post: 04-20-2009, 08:00 AM
  3. help to delete
    By andykots in forum Advanced Java
    Replies: 1
    Last Post: 01-29-2009, 08:29 AM
  4. Delete
    By Sarinam in forum New To Java
    Replies: 6
    Last Post: 07-23-2008, 11:09 AM
  5. how does the remove method work for sets and hashsets
    By haridharna in forum Advanced Java
    Replies: 4
    Last Post: 08-06-2007, 12:48 PM

Posting Permissions

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