Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jim829

Thread: Choose file name based on user input

  1. #1
    casta is offline Member
    Join Date
    Apr 2016
    Posts
    27
    Rep Power
    0

    Default Choose file name based on user input

    Hi,

    I want the user of my java program to select a date. The dataset corresponding to that date needs to be imported then.
    How am I able to select the right file?

    what I would like to have is:

    In my main:
    Java Code:
     
    String date = "27-05-2016";
    In another class that imports data:
    Java Code:
                File myFile = new File("src/27-05-2016Data.txt");
    In another class with different data
    Java Code:
                File myFile = new File("src/27-05-2016Data2.txt");

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Choose file name based on user input

    Do you have a specific java programming question?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Choose file name based on user input

    Read in the date via the Scanner class or a text field. Then create the file name with the path like so:

    Java Code:
    String file = "src/" + inputDate + "Data.txt";
    File myFile = new File(file);
    Regards,
    Jim
    casta likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Retrieving data from database based on user input
    By Madhatter40 in forum New To Java
    Replies: 5
    Last Post: 01-19-2015, 01:08 AM
  2. Displaying a square based on user's input
    By luke in forum New To Java
    Replies: 15
    Last Post: 07-14-2012, 09:43 AM
  3. Creating an object based on user input parameters
    By monkeyhead in forum New To Java
    Replies: 5
    Last Post: 11-14-2011, 11:59 PM
  4. How do I retrieve data based on user input?
    By tunali2 in forum New To Java
    Replies: 1
    Last Post: 04-03-2011, 02:40 PM
  5. Creating a number of objects based on user input.
    By Kevinius in forum New To Java
    Replies: 21
    Last Post: 04-03-2011, 08: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
  •