Results 1 to 2 of 2
  1. #1
    ohytheng's Avatar
    ohytheng is offline Member
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default Delete Empty Spaces...

    I got a jtxtfieldPath declare at up there to receive folder path from the user.

    Then at the event handling part,this is the code:

    File f1=new File(jtxtfieldPath.getText());

    If the user input something like this at the text field,it will crash:

    C:\users\aaa aaa aaa

    It is because of the space...

    What do I need to modified at the jtxtfieldPath.getText() part in order to eliminate all the empty spaces?

    Thanks...

  2. #2
    markw8500's Avatar
    markw8500 is offline Senior Member
    Join Date
    Jul 2008
    Location
    Pennsylvania, USA
    Posts
    136
    Rep Power
    0

    Default

    It is not the empty spaces that are giving you trouble... it is the backslashes... You need to escape them with another "\"... so it will be:

    C:\\users\\aaa aaa aaa

    OR

    Java Code:
           String fileSep = System.getProperty( "file.separator" );
            String theFilePath ="C:"+fileSep+"Documents and Settings"+fileSep+"Manager"+fileSep+"my file test.txt";
            File file = new File(theFilePath);
    Who Cares... As Long As It Works...

Similar Threads

  1. Converting all spaces to Single Space
    By JordashTalon in forum New To Java
    Replies: 6
    Last Post: 02-26-2009, 01:26 AM
  2. How do i add spaces ~(very simple)
    By soc86 in forum New To Java
    Replies: 3
    Last Post: 11-02-2008, 02:01 AM
  3. Caesar and encoding with block spaces
    By Franneldort in forum New To Java
    Replies: 13
    Last Post: 10-30-2008, 04:48 PM
  4. Load URL that contains spaces?
    By barkster in forum Java Applets
    Replies: 0
    Last Post: 01-30-2008, 09:40 PM
  5. Help with a word, if it is divided by spaces
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:31 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
  •