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);
}
< /code>
Ich habe diesen Code probiert und es hat funktioniert. Ich mache eine Suche nach einer Datei in meinem Computer "C:". Die Datei kann alles von PDF bis Doc sein. Es wird von einem Doc VIwer oder PDF -Viwer mit meinem Computer geöffnet. Fenster.
Bildbeschreibung hier eingeben < /p>
Fehler beim Durchsuchen einer Datei in NetBeans ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post