Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This quote from the <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html" rel="noreferrer">Javadoc</a> might be helpful:</p> <blockquote> <p>A pathname, whether abstract or in string form, may be either <em>absolute</em> or <em>relative</em>. An absolute pathname is complete in that no other information is required in order to locate the file that it denotes. A relative pathname, in contrast, must be interpreted in terms of information taken from some other pathname. By default the classes in the <code>java.io</code> package always resolve relative pathnames against the current user directory. This directory is named by the system property <code>user.dir</code>, and is typically the directory in which the Java virtual machine was invoked. </p> </blockquote> <p>I interpret this so that if you create your <code>File</code> object with <code>new File("filename")</code> where <code>filename</code> is a relative path, that path will not be converted into an absolute path even by a call to <code>file.getAbsolutePath()</code>.</p> <p><strong>Update:</strong> now that you posted code, I can think of some ways to improve it:</p> <ul> <li>you could use a <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/FilenameFilter.html" rel="noreferrer">FilenameFilter</a> to find the desired files,</li> <li>note that <code>list</code> and <code>listFiles</code> return <code>null</code> for non-directory objects, so we need an extra check for that,</li> <li>you could also use <code>listFiles()</code> again in the inner loop, thus avoiding the need to create new <code>File</code> objects with hand-assembled paths. (Btw note that appending <code>\\</code> manually to the path is not portable; the proper way would be to use <code>File.separator</code>).</li> </ul> <p>The end result is</p> <pre><code>private static void doSomethingToDirectory(File factDir) throws IOException { if (factDir.isDirectory()) { for (File file : factDir.listFiles()) { if (file.isDirectory()) { for (File child : file.listFiles(new MyFilter())) { process(child); } } } } } class MyFilter implements FilenameFilter { public boolean accept(File dir, String name) { return name.equals(TEMP_COMPARE_FILE); } } </code></pre> <p>Note that this code mimics the behaviour of your original piece of code as much as I understood it; most notably, it finds the files with the proper name only in the <em>direct subdirectories</em> of <code>factDir</code>, nonrecursively.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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