March 2018
Intermediate to advanced
208 pages
4h 52m
English
| | class Logbook { |
| | |
| | void writeMessage(String message, Path location) throws IOException { |
| » | if (Files.isDirectory(location)) { |
| | throw new IllegalArgumentException("The path is invalid!"); |
| | } |
| » | if (message.trim().equals("") || message == null) { |
| | throw new IllegalArgumentException("The message is invalid!"); |
| | } |
| | String entry = LocalDate.now() + ": " + message; |
| | Files.write(location, Collections.singletonList(entry), |
| | StandardCharsets.UTF_8, StandardOpenOption.CREATE, |
| | StandardOpenOption.APPEND); |
| | } |
| | } |
The first exception that beginners in Java typically see is the NullPointerException. It’s triggered if you call a method or access an attribute on a reference that is ...