Results 1 to 3 of 3
  1. #1
    aks123 is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Smile File path validation in Java

    I need a help regarding file handling in Java.
    I want to create a new file on windows m/c.User provides the dynamic path where we have to create the file.
    Path may contains absolute path or relative path or simple file name.
    I also want to display custome message if path provided by user is wrong.
    Some scenarios listed here -
    1) z:\ - wrong drive name it must give error message.
    2) c:\NewFile.txt - correct file name with correct path should create a file.
    3) c:\Testdata - exisiting folder on drive then should give the error message.
    4) c:\TestData123\NewFile.txt -invalid path, folder TestData123 is not exist on drive it should give error message.

    Please provide your valuable suggestions.

    -Aks

  2. #2
    aks123 is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default

    isDirectory() method will not work for invalid/non existing drive like z:\

  3. #3
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    6

    Default

    File.listRoots() will give you a list of the valid root drives.
    File.exists() will tell you if a file or directory already exists.

    Read the File class API.

Similar Threads

  1. reading file from a path
    By new_coder in forum New To Java
    Replies: 5
    Last Post: 08-17-2009, 04:52 AM
  2. find file with * on the path
    By itaipee in forum New To Java
    Replies: 7
    Last Post: 07-08-2009, 08:05 AM
  3. How to set Image file path
    By anil.bharadia in forum AWT / Swing
    Replies: 1
    Last Post: 01-28-2009, 09:10 PM
  4. how can i give a file path to java stream ?
    By sheckoo in forum New To Java
    Replies: 2
    Last Post: 11-05-2008, 08:42 AM
  5. file path
    By Arsench in forum New To Java
    Replies: 7
    Last Post: 10-30-2008, 05:39 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
  •