Results 1 to 3 of 3
- 04-29-2009, 04:06 PM #1Member
- Join Date
- Feb 2009
- Rep Power
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!!
- 04-29-2009, 04:16 PM #2
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.
- 04-29-2009, 04:51 PM #3
- By Alvaro in forum New To JavaReplies: 7Last Post: 01-16-2010, 12:02 AM
- By freezea in forum Reviews / AdvertisingReplies: 0Last Post: 04-17-2009, 02:27 PM
- By dedachi in forum AWT / SwingReplies: 3Last Post: 03-23-2009, 05:47 AM
- By new_1 in forum New To JavaReplies: 6Last Post: 12-25-2007, 08:38 AM