
Check that file exists (different programming languages) - sova
https://www.rosettacode.org/wiki/Check_that_file_exists
======
lazyant
In terms of being concise, Scheme wins by a mile, honorable mention for
Clojure (one-liner)

~~~
Viliam1234
The examples in different languages are not really comparable, because they do
different things.

For example, the Java code has 18 lines. Ha-ha, sure, we all know the popular
stereotype. But when you look at the actual code...

Lines 3-6 are just a wrapper that allows you to write
'isFileExists("input.txt")' instead of 'new File("input.txt").exists()'. Note
that the latter is the correct answer, and surprisingly also happens to be a
one-liner! The entire exercise could have ended right here, why write a
wrapper? Look at the Groovy solution, and replace 'println ...' with
'System.out.println(...)'.

The unnecessary wrapper also happens to be unnecessarily long. You don't have
to assign the result of a function call into a boolean variable, and then
return it in a separate statement. You can return the result of the function
call directly. It would even result in a shorter line!

(Also, why would anyone call a function 'isFileExists' instead of shortly and
more simply 'fileExists'? Starting function names with "is" is a Java
convention for getters, but this is not the case here; this function could not
be a getter, because it is static.)

Lines 7-11 print a formatted result on standard output. Examples in many
languages simply return the value.

An idiomatic Java solution comparable to solutions in other languages would be
something like this, including all the boilerplate code:

    
    
        package example;
        import java.nio.file.*;
        class Example {
            public static void main(String arguments...) {
                Stream.of("input.txt", "/input.txt", "docs", "/docs").forEach(s ->
                  System.out.println("" + s + Files.exists(Paths.get(s)) ? " exists" : " does not exist"));
            }
        }

