• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

file dialog

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we provide the sample code just like file tag in html.
ie. we have browse button and when u select the browse button u can select the file i your computer or create one file in specified directory in one computer.i have used filechooser.but unable toperform the operation just like file tag in html
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I fully understand your request. Did you check out the Java tutorial section on JFileChooser? It contains information on how to display the appropriate type of dialog. You can configure it for Open, Save, directories or files only, and so on.

You only really use JFileChooser to get File instances using the getSelectedFile() method. Once you have this you can find the path of the selected file and then take the appropriate action (create it if the action is a save; open the file and read it for loading; just display the path as a string for information, etc).
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using JFileChooser we can retreive a file by using getSelectedFile().
like that can we create one file under specified directory.if so tellme by which we can do this.i have tried .but no method haven't seen
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect you want your JFileChooser only to select directories,
then you can make a new file in the selected directory?

Very roughly, something like this:

JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = chooser.showOpenDialog(component);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File directory = chooser.getSelectedFile();
File babyFile = new File(directory,"name_of_babyfile);
};
//etc....

of course baby-file does NOT exist: you still have to create it on disk
with FileWriter or FileOutputStream....

Hope I helped you!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic