Results 1 to 3 of 3
  1. #1
    Juuno is offline Member
    Join Date
    Feb 2009
    Posts
    18
    Rep Power
    0

    Default dynamically search user input files

    When we want to open a file from java program, we use the following syntax.
    File namefile = new File ("file-path\\file-name");
    eg. File namefile = new File("C:\\Workspace\\myapplication\\mydata.xml")

    But instead of that 'mydata.xml', i would like to get the file name from the user input and accept it with variable and then I will search it whether it exists in the folder I specified, in that case, I know the location except the file name coz the user will input it.

    File namefile = new File("C:\\Worksapce\\myapplication\\variable-for-user-input")

    how can I do this?

    Thanks in advance!!

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Use some glue :-)

    Use the Scanner class to get the user's file name (if from command prompt) or JOptionPane class if GUI based and then just tack it on to your path:

    File namefile = new File("C:\\Worksapce\\myapplication\\" + variable-for-user-input);
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

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

    Default

    Also check out JFileChooser... This way you do not have to deal with incorrect user input... If your app is GUI...
    Who Cares... As Long As It Works...

Similar Threads

  1. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-15-2010, 11:02 PM
  2. Change data source dynamically while updating web input report
    By freezea in forum Reviews / Advertising
    Replies: 0
    Last Post: 04-17-2009, 02:27 PM
  3. User input- Pop Up Box
    By dedachi in forum AWT / Swing
    Replies: 3
    Last Post: 03-23-2009, 04:47 AM
  4. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 07:38 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
  •