Files and I/O


  1. How to copy the file from one location to other?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Files.copy(source, target) is used to copy a file from one location to another. There are various options available like REPLACE_EXISTING, COPY_ATTRIBUTES and NOFOLLOW_LINKS.


  1. How can we get the size of specified file?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    size(Path) returns the size of the specified file in bytes.



  1. How to read entire file in one line using java 8?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Java 8 provides Files.readAllLines() which allows us to read entire file in one task. We do not need to worry about readers and writers.


  1. How can we create a symbolic link to file?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    createSymbolicLink() creates a symbolic link to a target.



  1. How can we filter lines based on content?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    lines.filter(line -> line.contains(“===—> Loaded package”)) can be used to filter out.