Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:11:49+00:00 2026-06-17T09:11:49+00:00

I want to write a short application . It must browse the files to

  • 0

I want to write a short application . It must browse the files to seek the folders. If it find a folder, it write on console the name of folder and to into the folder. Next write to console name of txt files included in folder.

My code :

import java.io.File;

public class test {
    public static void search(File f) {

        File[] tab = f.listFiles();
        for (File file1 : tab) {
            if (file1.isDirectory()) {
                search(file1);
            } else {
                if (Txt(file1)) {
                    System.out.println("+ " + file1);
                }
            }
        }
    }

    public static boolean Txt(File f) {
        return f.getName().substring(f.getName().length() - 4).equals(".txt");
    }

    public static void main(String[] args) {
        try {
            File f = new File("/home/mati/Pulpit");
            search(f);
        } catch (Exception e) {
        }

    }
}

Result of code :

+ New Folder
    - aaa.txt
    - abc.txt
    - abf.txt
+ New Folder2
    - abgh.txt

My program write only txt files , and i dont know how fix it …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:11:50+00:00Added an answer on June 17, 2026 at 9:11 am

    Two things: first, to display the folder names, you will need to add a System.out in the branch of the code with the “if (file1.isDirectory())” conditional. You have a System.out in the “else” portion already, which is why the file names are displaying.

    Secondly, though, this will probably not work the way you want it to if you have folders inside of folders. All folders will display with one level of indentation, and all of the files will display with the other. But you won’t be able to see which folders are nested in the others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want write a little code analyzer which parses nested structures and translates into
Hello I want write my own desktop sharing application in Java. The application should
I want to write an application that would be a custom SSH server with
I want to write application on android and windows which will use bluetooth. In
I want to write a Java EE web application where different users work with
I'm trying to write a simple demo application in C++. I just want to
In short: I want to monitor selected calls from an application to a DLL.
I want to write an application that gets events on every file change on
I want write a simple query which will fetch data from a table (which
I want to write a batch script statement where: FINDSTR has to check for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.