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

  • Home
  • SEARCH
  • 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 8825009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:46:30+00:00 2026-06-14T06:46:30+00:00

help make this, the following code finds the txt files in the folder, and

  • 0

help make this, the following code finds the txt files in the folder, and how to make it lists the names of files without extensions. Here’s the code:

String list[] = new File("C:\\Users\\Eric\\Desktop\\txt\\").list(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return name.endsWith(".txt");
    }
});
for (int i = 0; i < list.length; i++){
    if(myName.equals(list[i])) {
        InputStreamReader reader  = null;
        try{
            File file =  new File("C:\\Users\\Eric\\Desktop\\txt\\" + list[i]);
            reader =  new InputStreamReader(new FileInputStream(file), "UTF-8");

As you can see, right here:

if(myName.equals(list[i]))

Here is the list of files is compared to the value of myname, so could you help give to the comparison sheet and myName and list[i], the file extension was not considered)
such as the program displays that folder has the following layout: indeks.html hi.html, user entered indeks.html, compare and good, but how to create one so that the user has entered the code, and the program still has compared it with the list of files in directory?

  • 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-14T06:46:32+00:00Added an answer on June 14, 2026 at 6:46 am

    If I understand correctly, you want to list all files in a folder, regardless of their extension. In this case, use:

    String list[] = new File("C:\\Users\\Eric\\Desktop\\txt\\").list(new FileFilter() {
        public boolean accept(File file) {
            return file.isFile();
        }
    });
    

    Edit: Ok, I did not understand you correctly. You want to strip the extension from the file name in your if statement. You can use substring combined with lastIndexOf:

    String name = list[i];
    String nameWithoutExtension = name.substring(0, name.lastIndexOf("."));
    

    or, since all your extensions are “.txt”, the following will work too:

    String nameWithoutExtension = name.substring(0, name.lastIndexOf(".txt"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could you help me to make this query faster. My query is workable, but
1) Custom exceptions can help make your intentions clear. How can this be? The
This is beyond my level and I need some help. In the htaccess make
Who can help me make the following query work... Both tables have the fields
first time post here. I was hoping someone could help me make custom SPARQL
I am using following code to convert string to sha1 string but i am
I have written the following code which works, but im wondering can I make
Couldn't find anything relevant in forums So ,Please help me with this code .I'm
I have been trying to find ways to make the following piece of code
I'm in trouble trying to make this code to work. What I'm trying to

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.