Note that there are some explanatory texts on larger screens.

plurals
  1. POIOException when passing Filefilter as argument
    primarykey
    data
    text
    <p>I have this strange problem when I execute this piece of code:</p> <pre class="lang-java prettyprint-override"><code>cdrFiles = dir.list(filter); System.out.println("cdrFiles length: " + cdrFiles.length); if (cdrFiles.length &gt;= 1) { System.out.println("there is 1 or more files"); }else{ throw new IOException("1No files in dir: " + directory + " that match the correct pattern"); } </code></pre> <p>The directory here contains 1 file that matches the filter.</p> <p>The output is:</p> <pre><code>cdrFiles length: 0 java.io.IOException: 1No files in dir: cdrs that match the correct pattern </code></pre> <p>When I comment the exception:</p> <pre class="lang-java prettyprint-override"><code>cdrFiles = dir.list(filter); System.out.println("cdrFiles length: " + cdrFiles.length); if (cdrFiles.length &gt;= 1) { System.out.println("there is 1 or more files"); }else{ //throw new IOException("1No files in dir: " + directory + " that match the correct pattern"); } </code></pre> <p>I get this output:</p> <pre><code>cdrFiles length: 1 there is 1 or more files </code></pre> <p>Does anyone know how this is possible?</p> <p><em>EDIT:</em></p> <p>This is the code for the filter:</p> <pre class="lang-java prettyprint-override"><code>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")); } }); </code></pre> <p>With the first code the filename isn't printed.<br> With the second code it is (even checked if it matched -> yes)</p> <p>File in directory:</p> <pre><code>call_history_20111001_20111031_465_answer.csv </code></pre> <p>collectCdrFiles function look like this:</p> <pre><code>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 &gt;= 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; } </code></pre> <p>same problem with this code:</p> <pre><code>if (cdrFiles.length &gt;= 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"); } </code></pre> <p>SSCCEE:</p> <pre><code>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 &gt;= 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."); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload