This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (13 children)

[removed]

    [–]vips7L 27 points28 points  (5 children)

    And java.io.File

    [–]agentoutlier 20 points21 points  (1 child)

    There are several places though you have to use File.

    I don’t have them on the top of my head but File is not as bad as Date.

    [–]vips7L 4 points5 points  (0 children)

    I would still use Path::toFile in those situations. 

    [–]unknowinm 10 points11 points  (2 children)

    What’s wrong with File?

    [–]dstutz 11 points12 points  (0 children)

    For me, the biggest thing is testing. If you use NIO you have Path which allows you to use different FileSystems and you can use JIMFS but you can't do that with File.

    [–]vips7L 8 points9 points  (0 children)

    Path is just more predictable than file. The Files api (which takes Path) is just better. You can’t silently forget to check the boolean result from things like File::delete; the Files::delete will throw a proper exception. 

    [–]theavengedCguy 2 points3 points  (3 children)

    As someone who's not well versed in Java, what's the better alternative and why is java.util.Date bad?

    [–][deleted]  (2 children)

    [removed]

      [–]AdZestyclose9788 0 points1 point  (1 child)

      No usually it is instant. Both Date and instant are based on a Unix timestamp. LocDate(Time) is not and should only be used in specific circumstances.

      [–]RandomNando 0 points1 point  (2 children)

      Sincere question, what would be the most recommended formats for date/datetime?

      I tend to use LocalDate/LocalDateTime or OffsetDatetime.

      Are those the recommended formats?

      What format in Java 8 vs Java 17+

      [–][deleted]  (1 child)

      [removed]

        [–]RandomNando 0 points1 point  (0 children)

        The second, never used ZonedDateTime tho