Java File Explorer program with Source Code

Let’s develop a basic file explorer using java. Java’s FILE class from java.io package provides simple way to represent both files and directories. That means, the same class can represent both files and directories.
This program starts by creating a new file in the root. For example we can start at C drive in windows or root(/) in Linux.


File f = new File(“C:\”);  


The list of available files and folders present in the given directory can be accessed using the function listFiles(). It returns a list of files pointing to the contents inside the directory. Using a for loop buttons are created dynamically for each of these files and added to the container panel.
Handling Files
 
The button can be either file or folder. Using isFile() function in the FILE class, it is possible to determine whether a file is a file or directory. If it is a file, we then have to open it, if possible.
Java provides a powerful handle to the operating system using ‘Desktop’ class from java.awt package. Using Desktop we can open a file using the default program associated for it.
Desktop.getDesktop().open(FileName); 
Open() throws an IOException and should be caught properly.
Handling Directories
When we encounter a directory, which is the false case for isFile(), we have to display the contents in that directory. What we have to do here is a simple recursive call to the display function using this path after removing the all currently present components in the container.
Container.removeAll() should do the trick.
After adding the new buttons, it is necessary to refresh the panel. Remember that the newly added components will not be visible until you refresh the panel using revalidate() and repaint() functions present in the Panel class.
container.revalidate();  
 container.repaint(); 
Adding a back button
It is a basic requirement for File explorers to add back buttons. In order to do so, we have to remember the history of directories. A stack is used for this purpose. Whenever a directory is accessed, its parent is added to the stack. When the back button is pressed, the top of the stack is popped and that directory is displayed.
Go to directory
Again, the same display function LoadBase() is utilized here. LoadBase taked the full pathname of directory and when the user gives the directory path directly, all that we have to do is to pass the given text to LoadBase(). The path may be invalid and it is displayed using message dialog. isExist() function in the file class helps to check whether a file/directory exists.

 
Download Project  

Main Window screenshot for Java File Explorer
Loaded C Drive
D drive listed using Java File Explorer
Using Go to to load D drive

Comments

40 responses to “Java File Explorer program with Source Code”

  1. Paul Miller Avatar

    Thanks for sharing this information in here. As a fresher any one can also go for the below training programs.
    Java Training in Chennai|Java Courses in Chennai

  2. Jhon anderson Avatar

    Wonderful post.This is really one of the most beneficial blogs I’ve ever browsed on this subject. I am very glad to read such a great blog and thank you for sharing this good information with us.
    Regards,
    JAVA Training in Chennai | Java Courses in Chennai | J2EE Training in Chennai

  3. for IT the Avatar

    I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

  4. Johny Ledge Avatar
    Johny Ledge

    The Spring Framework is a lightweight framework for developing Java enterprise applications. It provides high performing, easily testable and reusable code. Spring handles the infrastructure as the underlying framework so that you can focus on your application.Spring is modular in design, thereby making creation, handling and linking of individual components so much easier. Spring implements Model View Container(MVC) design pattern.spring mvc validation example

  5. Proplus Academy Avatar
    Proplus Academy

    Hi Good day….

    Excellent post and very useful for everyone…keep updating
    php training in coimbatore

    seo training in coimbatore

    web design training coimbatore

    digital marketing training in coimbatore

  6. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  7. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  8. … [Trackback]

    […] Info on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  9. … [Trackback]

    […] Read More Information here on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  10. … [Trackback]

    […] Info on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  11. … [Trackback]

    […] Find More on to that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  12. … [Trackback]

    […] Info on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  13. … [Trackback]

    […] There you can find 20370 more Info on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  14. … [Trackback]

    […] Info to that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  15. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  16. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  17. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  18. … [Trackback]

    […] Find More Information here to that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  19. … [Trackback]

    […] There you will find 39214 additional Information on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  20. … [Trackback]

    […] Info on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  21. … [Trackback]

    […] Info on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  22. … [Trackback]

    […] Read More Info here to that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  23. … [Trackback]

    […] Find More on on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  24. … [Trackback]

    […] Info on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  25. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  26. … [Trackback]

    […] There you will find 32247 more Information to that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  27. … [Trackback]

    […] Find More to that Topic: genuinecoder.com/directory-folder-indexing-program-using-java-source-code-html/ […]

  28. kamagra nourris pendant la nuit sans ordonnance

    kamagra livraison fedex gratuite

  29. buy cheap enclomiphene canadian sales

    how to order enclomiphene generic form

  30. buy androxal cheap no prescription

    ordering androxal generic mastercard

  31. Buy flexeril cyclobenzaprine no prior script overnight

    Buy flexeril cyclobenzaprine online without a script

  32. online order dutasteride cheap melbourne

    discount dutasteride where to purchase

  33. cheap gabapentin purchase online uk

    cheap gabapentin no prescription usa

  34. itraconazole comprar itraconazole generico

    ordering itraconazole cost new zealand

  35. ordering fildena purchase online from india

    US pharmacies for fildena without rx

  36. staxyn without a perscription

    cheap staxyn uk buy online

  37. cheap avodart usa sales

    online order avodart buy hong kong

  38. purchase rifaximin cheap fast shipping

    buying rifaximin purchase tablets

  39. buying xifaxan australia discount

    buy xifaxan generic switzerland

  40. chci pナ册dpis kamagra

    objednejte kamagra bez lテゥkaナ冱kテゥho pナ册dpisu od naナ。テュ lテゥkテ。rny

Leave a Reply