Results 1 to 4 of 4

Thread: file pathname

  1. #1
    lemontree45 is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default file pathname

    Hi,

    I am using netbeans and have created a form in JavaSwing where I could browse a file and its pathname is displayed in a text field.

    The code used for creating that event is as follows.
    Java Code:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
           
            int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            
         // What to do with the file, e.g. display path of the file in a Textfield
    
              jTextField1.setText(fileChooser.getSelectedFile().getAbsolutePath());
          
            } 
        }

    Now, I need to use this pathname in the 'jTextField1' in another class and it should be displayed for eg:"C:\\chinese.txt" instead of C:\chinese.txt as it is given in the jTextField.

    Could someone clarify it please?

    Thanks and Regards

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    Plug in this line of code and execute it:
    Java Code:
    System.out.println("C:\\chinese.txt");
    The double backslash is only needed in String literals, because the backslash is the escape character.

    Go through this: Lexical Structure

    db

  3. #3
    lemontree45 is offline Member
    Join Date
    Oct 2010
    Posts
    25
    Rep Power
    0

    Default

    No my question is actually, How can i use this pathname in the 'jTextField1' which is in the form of C:\chinese.txt and convert it into C:\\chinese.txt so that I can use it in the program. and this file pathname changes everytime, as I choose a different file.

    Thanks & Regards

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Why do you need to display 2 backslashes instead of one? If you plan on actually using the path to create a File object then as Daryl mentioned the double backslash is only needed in String literals in your code to get around the compiler. If you are reading the path in from some external source then the double backslash is not needed.

Similar Threads

  1. Replies: 1
    Last Post: 07-28-2011, 07:50 PM
  2. Replies: 6
    Last Post: 12-01-2010, 05:31 AM
  3. Replies: 0
    Last Post: 07-15-2010, 01:23 PM
  4. Replies: 8
    Last Post: 02-18-2010, 12:54 PM
  5. Replies: 0
    Last Post: 02-11-2009, 09:53 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
  •