Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008, 03:37 PM
Member
 
Join Date: May 2008
Posts: 11
bachtoutou is on a distinguished road
How to create a directory using the library java.io
Hello evrybody
T want to create a directory which name exists in a JtextField "app" and the path is in a JtextField "mod".This directory is create when i press the button Jbutton2.I have developed a code but it dosen't create anything
Code:
private void jButton2_actionPerformed(ActionEvent e) { File fichier=new File (app.getText()); File fichier_parent=new File (mod.getText()); fichier_parent.mkdirs(); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-18-2008, 06:40 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
What about mkdir() method?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-23-2008, 06:21 PM
Member
 
Join Date: May 2008
Posts: 2
radtad82 is on a distinguished road
mkdirs is a better method to use, since it will create any parent directories as well.
My guess is there's something wrong with the way the path is specified. Are you sure the complete path is specified?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-24-2008, 12:08 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.event.*; import java.io.File; import javax.swing.*; public class MakeFiles { private JPanel getContent() { final JTextField fileName = new JTextField(12); final JTextField parentName = new JTextField(12); JButton button = new JButton("make files"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String name = fileName.getText().trim(); String parent = parentName.getText().trim(); System.out.printf("check for file %s in %s%n", name, parent); File file = new File(parent, name); if(file.exists()) System.out.println("files exist"); else file.mkdirs(); } }); JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(2,2,2,2); gbc.weighty = 1.0; gbc.gridwidth = GridBagConstraints.RELATIVE; panel.add(new JLabel("file name"), gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; panel.add(fileName, gbc); gbc.gridwidth = GridBagConstraints.RELATIVE; panel.add(new JLabel("parent file name"), gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; panel.add(parentName, gbc); gbc.gridwidth = 2; panel.add(button, gbc); return panel; } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new MakeFiles().getContent()); f.setSize(300,160); f.setLocation(200,200); f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create directory through Java Code Java Tip java.io 0 04-04-2008 04:44 PM
Which Java-XML library or technology is best for my needs? nitingupta183 Advanced Java 1 03-15-2008 08:34 AM
Create a new directory in existing Zip archive satishbejgum Advanced Java 1 12-23-2007 08:05 AM
Java Machine Learning Library 0.0.12 JavaBean Java Announcements 0 10-20-2007 07:56 PM
java.lang.UnsatisfiedLinkError: no parport in java.library.path Heather NetBeans 2 06-29-2007 04:45 PM


All times are GMT +3. The time now is 10:36 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org