Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i delete directory in java using JFileChooser
    primarykey
    data
    text
    <p>I am beginner in java please tell me what is the problem in following code..not delete directory or file. I am makin GUI application for delete directory. </p> <pre><code>import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; class DeleteFile extends JFrame implements ActionListener { JFileChooser fc; JButton b, btndel; JLabel l; JTextField tf; DeleteFile() { super("Delete Directory"); fc = new JFileChooser("G:\\Java"); l = new JLabel("File"); l.setBounds(25, 22, 35, 35); add(l); tf = new JTextField(); tf.setBounds(60, 25, 170, 25); add(tf); b = new JButton("Browse"); b.setBounds(250, 25, 80, 25); add(b); b.addActionListener(this); btndel = new JButton("Delete"); btndel.setBounds(250, 100, 80, 25); add(btndel); btndel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getSource() == btndel) { String text = tf.getText(); System.out.println(text); File del = new File("text"); delete(del); } } }); setLayout(null); setSize(400, 200); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == b) { int x = fc.showOpenDialog(null); if (x == JFileChooser.APPROVE_OPTION) { File f1 = fc.getSelectedFile(); String s1 = fc.getName(f1); tf.setText(s1); File f2 = fc.getCurrentDirectory(); String s2 = fc.getName(f2); } } } public void delete(File file) { if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i &lt; files.length; i++) { delete(files[i]); } file.delete(); System.out.println("yes"); } else { file.delete(); System.out.println("no"); } } public static void main(String... s) { new DeleteFile(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload