Всем привет! Столкнулся с проблемой при работе с файловыми дисками. Хочу написать собственную программу для поиска и удаления ненужных файлов, но когда использую File.listRoot(), то туда попадают и компакт-привод и флоппик. И когда мой код обращается например к флоппику, то выдается предупреждение что диск не готов. Как мне средствами Java обойти это надоедливое предупреждение? Например, если в дисковод не вставлена дискета, то поиск начинается с следующего диска автоматичесски. Как так сделать? Вот пример кода приложения:
package indicator;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.io.File;
public class FrameDelete extends JFrame {
JPanel contentPane;
JButton jButton1 = new JButton();
XYLayout xYLayout1 = new XYLayout();
File arrayCatalog[];
/**Construct the frame*/
public FrameDelete() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
jButton1.setText("Поиск");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
//setIconImage(Toolkit.getDefaultToolkit().createImage(FrameDelete.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(xYLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
contentPane.add(jButton1, new XYConstraints(20, 20, 81, -1));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public void AddCatalog(File arrayFile) {
File arrayFiles[];
arrayFiles = arrayFile.listFiles();
int j=0;
for(j=0;j<arrayFiles.length;j++){
if (arrayFiles[j].isDirectory()){
this.AddCatalog(arrayFiles[j]);}
else{
System.out.println(arrayFiles[j]);}
}
}
void jButton1_actionPerformed(ActionEvent e) {
File file;
File arrayFiles[];
try {
File[] disk = File.listRoots();
int i=0;int j=0;
for(i=0;i<disk.length;i++){
file = new File(disk[i].toString());
if (disk[i].canWrite()) {
arrayFiles = file.listFiles();
for(j=0;j<arrayFiles.length;j++){
if (arrayFiles[j].isDirectory()){
this.AddCatalog(arrayFiles[j]);}
else{
System.out.println(arrayFiles[j]);}
}
}
}
} catch (java.lang.ArrayIndexOutOfBoundsException eb){
}
}
}