Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java program scan folder find files using time

import java.io.*;
import java.util.*;
import java.awt.Desktop;
public class Filesearch2 {


    public static void main(String[] args)throws IOException {        
        Filesearch2 fs = new Filesearch2();
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter the file to be searched.. " );
        String name = scan.next();
        System.out.println("Enter the directory where to search ");
        String directory = scan.next();
        fs.findFile(name,new File(directory));
    }
    public void findFile(String name,File file1)throws IOException
    {      
        File[] list = file1.listFiles();       
        if(list!=null)  
     {                          
        for(File file2 : list)
        {            
            if (file2.isDirectory())
            {
                findFile(name,file2);             
            }
            else if (name.equalsIgnoreCase(file2.getName()))
            {                                                              
                System.out.println("Found");                
                System.out.println("File found at : "+file2.getParentFile());
                System.out.println("Path diectory: "+file2.getAbsolutePath());
                String p1 = ""+file2.getParentFile();
                File f2 = new File(p1);
                Desktop.getDesktop().open(f2);                               
            }                      
        }        
      }
    }        
}
Comment

java program scan folder find files using time

import java.io.*;
import java.util.*;
import java.awt.Desktop;
public class Filesearch2 {


    public static void main(String[] args)throws IOException {        
        Filesearch2 fs = new Filesearch2();
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter the file to be searched.. " );
        String name = scan.next();
        System.out.println("Enter the directory where to search ");
        String directory = scan.next();
        fs.findFile(name,new File(directory));
    }
    public void findFile(String name,File file1)throws IOException
    {      
        File[] list = file1.listFiles();       
        if(list!=null)  
     {                          
        for(File file2 : list)
        {            
            if (file2.isDirectory())
            {
                findFile(name,file2);             
            }
            else if (name.equalsIgnoreCase(file2.getName()))
            {                                                              
                System.out.println("Found");                
                System.out.println("File found at : "+file2.getParentFile());
                System.out.println("Path diectory: "+file2.getAbsolutePath());
                String p1 = ""+file2.getParentFile();
                File f2 = new File(p1);
                Desktop.getDesktop().open(f2);                               
            }                      
        }        
      }
    }        
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to show the hex detail of a file in java 
Java :: Java Access Members of a Class 
Java :: compare string length of two strings 
Java :: stop countdown timer when exiting an activity 
Java :: java unfocus 
Java :: set skin minecraft entity player 
Java :: leerzeichen ersetzen java 
Java :: Which type of Exception will be thrown by forName() method 
Java :: Java the implements this function will return a copy of the original String that has all characters replaced with plus signs ("+"), with the exception of word string appearances, which are left alone. 
Java :: how to make jframe full screen 
Java :: how does minus works in Java 
Java :: Mirror Inverse Program in java 
Java :: java Generate parentheses all combinations 
Java :: expandablelistview android 
Java :: how to extract a set of binary strings in java 
Java :: bluetooth chat example android server 
Java :: Java Target annotations attributes 
Java :: How do you input numbers into an array? 
Java :: what isz meaning of EL in jsp 
Java :: min_value java 
Java :: how to write a java program for printing child or adult in java 
Java :: Example of ArrayDeque 
Java :: reset status bar color in android 
Java :: system.out.print 
Java :: Determining what type of data the ArrayList will contain in java. 
Java :: Recyclerview scramble after scrolling 
Java :: hash tree in java 
Java :: what is inheritance in java 
Java :: java digit in number 
Java :: instanceof operator java 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =