Reputation: 1
private void SearchbtnActionPerformed(java.awt.event.ActionEvent evt) {
String answer1 = TxtFi.getText();
Scanner sc = new Scanner(answer1);
name = sc.nextLine();
try {
getRootPath();
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void getRootPath() throws IOException {
File[] files = File.listRoots();
for (File f : files) {
System.out.println(f.getPath());
parseAllFiles(f.getPath());
if (count == 1) {
}
if (count > 1) {
}
}
}
public static void parseAllFiles(String parentDirectory) {
File[] filesInDirectory = new File(parentDirectory).listFiles();
File[] desktop = new File("C:\\PDF FILES").listFiles();
try {
if (filesInDirectory != null) {
for (File f : filesInDirectory) {
if (f.isDirectory() && !f.toString().startsWith(".")){
parseAllFiles(f.getAbsolutePath());
}
file = f;
path = f.toString();
if (file.getName().equalsIgnoreCase(name) || file.getName().toLowerCase().contains(name.toLowerCase())) {
count++;
fileX = file;
Desktop.getDesktop().open(fileX);
}
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new kainourgio2().setVisible(true);
}
I tried this code and it worked. I am making a search of a file in my computer C:\
. The file can be anything from pdf
to doc
. It opens from any doc viewer or pdf viewer that is on my computer.
The problem here is that when I click the exit button the frame does not close or exit.
I expect to do a lot of searching for files without the program crashing but now I can only do one search. I can't do anything else after the first search. It's like my program is stuck in an endless loop.
I do not see any error messages in the console or NetBeans output window.
Upvotes: 0
Views: 42