Check that file exists: Difference between revisions

Content added Content deleted
(Add libheader to the lang example)
Line 1,659: Line 1,659:
direxist '/docs'</syntaxhighlight>
direxist '/docs'</syntaxhighlight>
=={{header|Java}}==
=={{header|Java}}==
This can be done with a <code>File</code> object.<br />
<syntaxhighlight lang="java">
new File("docs/input.txt").exists();
new File("/docs/input.txt").exists();
</syntaxhighlight>
Zero-length files are not a problem, and return as existent.<br />
Java supports UTF-16, so the unusual file name is not a problem.
<syntaxhighlight lang="java">
new File("`Abdu'l-Bahá.txt").exists()
</syntaxhighlight>
<syntaxhighlight lang="java">
new File("`Abdu'l-Bah\u00E1.txt").exists();
</syntaxhighlight>
<br />
Alternately
<syntaxhighlight lang="java">import java.io.File;
<syntaxhighlight lang="java">import java.io.File;
public class FileExistsTest {
public class FileExistsTest {
Line 1,698: Line 1,713:
}
}
}</syntaxhighlight>
}</syntaxhighlight>

=={{header|JavaScript}}==
=={{header|JavaScript}}==
Javascript interpreters are now widely embedded in contexts which do have access to file systems, but the early context of browser scripting has precluded the inclusion of file system libraries in the definition of the language itself.
Javascript interpreters are now widely embedded in contexts which do have access to file systems, but the early context of browser scripting has precluded the inclusion of file system libraries in the definition of the language itself.