Results 1 to 4 of 4
- 05-18-2008, 01:37 PM #1
Member
- Join Date
- May 2008
- Posts
- 11
- Rep Power
- 0
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
Java Code:private void jButton2_actionPerformed(ActionEvent e) { File fichier=new File (app.getText()); File fichier_parent=new File (mod.getText()); fichier_parent.mkdirs(); }
- 05-18-2008, 04:40 PM #2
What about mkdir() method?
freedom exists in the world of ideas
- 05-23-2008, 04:21 PM #3
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
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?
- 05-23-2008, 10:08 PM #4
Java 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); } }
Similar Threads
-
java.lang.UnsatisfiedLinkError: no parport in java.library.path
By Heather in forum NetBeansReplies: 3Last Post: 09-07-2009, 01:28 PM -
How to create directory through Java Code
By Java Tip in forum java.ioReplies: 1Last Post: 04-14-2009, 03:34 PM -
Which Java-XML library or technology is best for my needs?
By nitingupta183 in forum Advanced JavaReplies: 1Last Post: 03-15-2008, 06:34 AM -
Create a new directory in existing Zip archive
By satishbejgum in forum Advanced JavaReplies: 1Last Post: 12-23-2007, 06:05 AM -
Java Machine Learning Library 0.0.12
By JavaBean in forum Java SoftwareReplies: 0Last Post: 10-20-2007, 05:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks