Results 1 to 3 of 3
  1. #1
    Pojahn_M's Avatar
    Pojahn_M is offline Senior Member
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    197
    Rep Power
    4

    Default Is java.io.File.getPath () broken?

    It seems like getPath is broken. It does not return the file path(with the file name removed).

    File file = new File ("C:\\Program\\hello.txt");
    System.out.println (file.getPath ());

    And the output will be C:\Program\hello.txt.
    The output should be C:\Program.
    Is it broken or am I misunderstanding this method?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: Is java.io.File.getPath () broken?

    Try some other methods to see what they do. There is probably one that will return what you want.

  3. #3
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default Re: Is java.io.File.getPath () broken?

    Quote Originally Posted by Pojahn_M View Post
    It seems like getPath is broken. It does not return the file path(with the file name removed).

    File file = new File ("C:\\Program\\hello.txt");
    System.out.println (file.getPath ());

    And the output will be C:\Program\hello.txt.
    The output should be C:\Program.
    Is it broken or am I misunderstanding this method?
    The method is doing exactly what it should be: getting the path to the file. If you want its folder's path then use String methods to get the folder by itself.

Similar Threads

  1. Unexpected text returned from getPath()
    By madroadbiker in forum New To Java
    Replies: 3
    Last Post: 04-23-2011, 05:51 PM
  2. Forum broken?
    By PhHein in forum Suggestions & Feedback
    Replies: 3
    Last Post: 07-08-2010, 06:16 PM
  3. Replies: 1
    Last Post: 09-10-2009, 02:58 PM
  4. still broken?
    By xcallmejudasx in forum Forum Lobby
    Replies: 1
    Last Post: 06-06-2009, 12:26 AM
  5. compiler broken please help
    By ryn21 in forum New To Java
    Replies: 4
    Last Post: 10-10-2008, 08:47 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
  •