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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:11:10+00:00 2026-05-26T22:11:10+00:00

I have this strange problem when I execute this piece of code: cdrFiles =

  • 0

I have this strange problem when I execute this piece of code:

cdrFiles = dir.list(filter);
System.out.println("cdrFiles length: " + cdrFiles.length);
if (cdrFiles.length >= 1) {
    System.out.println("there is 1 or more files");
}else{
    throw new IOException("1No files in dir: " + directory + " that match the correct pattern");
}

The directory here contains 1 file that matches the filter.

The output is:

cdrFiles length: 0
java.io.IOException: 1No files in dir: cdrs that match the correct pattern

When I comment the exception:

cdrFiles = dir.list(filter);
System.out.println("cdrFiles length: " + cdrFiles.length);
if (cdrFiles.length >= 1) {
    System.out.println("there is 1 or more files");
}else{
    //throw new IOException("1No files in dir: " + directory + " that match the correct pattern");
}

I get this output:

cdrFiles length: 1
there is 1 or more files

Does anyone know how this is possible?

EDIT:

This is the code for the filter:

String[] cdrFiles = collectCdrFiles(directory, new FilenameFilter() {

    public boolean accept(File dir, String name) {
        System.out.println(name + "\t" + name.matches("call_history_[0-9]{8}_[0-9]{8}_[0-9]{3}_answer.*\.csv"));
        return name.matches("call_history_[0-9]{8}_[0-9]{8}_[0-9]{3}_answer.*\.csv"));
    }
});

With the first code the filename isn’t printed.
With the second code it is (even checked if it matched -> yes)

File in directory:

call_history_20111001_20111031_465_answer.csv

collectCdrFiles function look like this:

protected String[] collectCdrFiles(String directory, FilenameFilter filter) throws IOException {
    //open cdr directory
    String[] cdrFiles;
    File dir = new File(directory);
    //get cdr files
    if (dir.exists()) {
        cdrFiles = dir.list(filter);
        System.out.println("cdrFiles length: " + cdrFiles.length);

        if (cdrFiles.length >= 1) {
            System.out.println("there is 1 or more files");
        }else{
            throw new IOException("1No files in dir: " + directory + " that match the correct pattern");
        }
    } else {
        throw new IOException("Directory: " + directory + " doesn't exist.");
    }
    return cdrFiles;
}

same problem with this code:

if (cdrFiles.length >= 1) {
    System.out.println("there is 1 or more files");
}
if(cdrFiles.length == 0){    
    throw new IOException("1No files in dir: " + directory + " that match the correct pattern");
}

SSCCEE:

public static void main(String[] args) throws IOException {
    String[] cdrFiles;
    File dir = new File("testfolder");
    //get cdr files
    if (dir.exists()) {
        cdrFiles = dir.list(new FilenameFilter() {

        public boolean accept(File dir, String name) {
        System.out.println(name + "\t" + name.matches("call_history_[0-9]{8}_[0-9]{8}_[0-9]{3}_answer.*\\.csv"));
        return name.matches("call_history_[0-9]{8}_[0-9]{8}_[0-9]{3}_answer.*\\.csv");
        }
    });
        System.out.println("cdrFiles length: " + cdrFiles.length);

        if (cdrFiles.length >= 1) {
        System.out.println("there is 1 or more files");
        }
        if(cdrFiles.length == 0){        
        throw new IOException("1No files in dir: " + dir.getName() + " that match the correct pattern");
        }
    } else {
        throw new IOException("Directory: " + dir.getName() + " doesn't exist.");
    }
    }
}
  • 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-26T22:11:11+00:00Added an answer on May 26, 2026 at 10:11 pm

    ANSWER

    I fixed the problem. Don’t know why, but when i pass the filter as argument it fails. All other ways (in-line or separate class) work with identical code

    so to still be able to pass it i did it like this:

    cdrFiles = collectCdrFiles(directory, new CdrFilenameFilterUnifiedTelecom().getClass());
    

    and in the function i instanciate the class:

    cdrFiles = dir.list((FilenameFilter)filter.newInstance());
    

    ugly as hell but it works ^^

    thx for the help guys

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

Sidebar

Related Questions

i am having a strange problem, i have a static class like this public
I have a bit of strange problem on this page: http://www.bluprintliving.com/locations it seems that
This is a quite strange problem. I have set a setting variable in Application
I have a strange problem. Using wsimport I generated als JAX-WS Code from a
I've have this strange problem when adding a column to an existing table. The
I have this strange call stack and I am stumped to understand why. It
I have this strange issue with my web app. You see, I'm using jQuery
This is a strange one... In a windows forms app (VB.NET/VS 2005) I have
Why this two functions have the strange behaviour of when I click on thead,
This a bit of strange one.... We have an internal web app that runs

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.