2

I am trying to open a folder from java program by using the following java code

Desktop.getDesktop().open(new File("d:\\abc"));

I can successfully opened d:\\abc, now this abc folder is having two sub folders images, and songs now my reuirement is to focus this folder then open it by depending on user given input at run time.

May be tomorrow these sub file names will be changed, but depending on user input i want to focus on corresponding sub folders and open them.

I tried lot of ways in google and stackoverflow also. But I didn't get proper way.

ComFreek
  • 29,044
  • 18
  • 104
  • 156
  • 2
    Once `Desktop.getDesktop().open(new File(..));` is called, the Java app. loses all 'control' of what happens after is it opened. Perhaps this app. needs [`JFileChooser`](http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html) instead. It allows more control and feedback for the app. – Andrew Thompson Jun 15 '14 at 11:38
  • 1
    BTW - what has this really got to do with Swing, or anything to do with speech? Voice controlled file browsing desktop app.? – Andrew Thompson Jun 15 '14 at 11:39
  • @AndrewThompson yes i am getting input from user as voice command –  Jun 15 '14 at 11:57
  • @AndrewThompson can please elaborate about JFileChooser :) –  Jun 15 '14 at 11:58
  • The link I included in my first comment elaborates quite nicely about `JFileChooser`. Can you please read it? :) – Andrew Thompson Jun 15 '14 at 12:18

2 Answers2

2

Use a JFileChooser to display the local file system and get the user's selection. Alternatively, add a suitable list or tree selection listener to one of the display components cited here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

You can use Robot class, by using this Robot class you can press key on keyboard programatically. If user input is

images

then user Robot class to press corresponding key programatically.

Here you can get tutorial on Robot class http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html

Jagadeesh
  • 862
  • 7
  • 23