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 5986193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:38:15+00:00 2026-05-22T22:38:15+00:00

I’m about to lose my mind on this one right here. I’d like to

  • 0

I’m about to lose my mind on this one right here. I’d like to compare 4 files with each other.

They’re split in 2 folders. So there is folder “A” with file 1-4
and there is folder “B” which is a copy of folder “A”.

package Aufgabe2;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;



class FTWalker {
    FTWalkerTWO two;

    public static void main(String[] args) throws IOException {
        new FTWalker().walk(args[0]);
    }

    void walk(String pathname) throws IOException {
        File[] files = new File(pathname).listFiles();
        List<Integer> list = new ArrayList<Integer>();
        List<String> liste2 = new ArrayList<String>();  
        int i = 0;


        if (files != null)
            for (File file: files)
                if (file.isDirectory())
                    walk(file.getCanonicalPath());
                else{
                    //      process(file.getCanonicalPath(), (int)file.length());
                    System.out.println(""+file.getName()); //gibt namen aus
                    list.add( (int) file.length());
                    liste2.add(file.getName());
                    i++;
                    duplikat(file,liste2);
                }
        //  sortiert(list);
    }

    void process(String name, int length) {
        System.out.printf("%-70s%9d%n", name, length);
    }

    void sortiert(List<Integer> a) {
        Collections.sort(a);
        for (int k = 0; k < a.size(); k++) {
            System.out.print(a.get(k) + " ");
        }
        System.out.println("");

        Comparator<Integer> comparator = Collections.<Integer> reverseOrder();
        Collections.sort(a, comparator);

        for (int k = 0; k < a.size(); k++) {
            System.out.print(a.get(k) + " ");
        }
    }

    public void duplikat(File file,List<String> a ){//stand vorher List<String> liste2 drin
      //for(int i.)
        if(file.getName().equals(a.get(i)){
            System.out.println("Yo\n");
        }else{
            System.out.println("Sorry seems to be the hardest word\n");
        }

    }
}

The code above gets a folder at args[0], walks through a directory which contains a couple of files and prints the whole path + the size of the file.

All I want is to see if the files name are equal or not!

I got z.txt in both folders – they are equal (name). Then I changed one of them to z2.txt. Now, I checked both have same name or not. But I don’t get the correct result.

  • 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-05-22T22:38:15+00:00Added an answer on May 22, 2026 at 10:38 pm

    You have several problems in that code.

    A naive solution is to replace the List with a Set and then add to it combination of file name and size.

    Other solution is to create a object that will contain the file name and the size of it. That will override the implementation of equals() and hashode(), and then use the HashSet to verify that a file of this type had been found.

    EDIT:

    As you need only check the file name without any other restriction only thing that you could use a Set where you can store the file name. As you are walking through file system you just need to verify that such name is all ready in the set. In addition you need to store the amount of already found file names. To handle this you can used a HashMap where key is file name and Value is the amount.

    if(nameMap.contains(file.getName()) {
    
      Integer index = nameMap.getValue(file.getName()) + 1;
    
       //rename file file.renameTo(new File(newPathWithIndex)));
    
    } else {
      nameMap.put(file.getName(), 0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.