Untitled
unknown
java
2 months ago
750 B
13
Indexable
public class IOTools {
public static IO<String> readFile(String path) {
File file = new File(path);
String content;
try (Scanner myReader = new Scanner(file)) {
content = myReader.hasNextLine() ? myReader.nextLine() : "";
} catch (FileNotFoundException e) {
content = "";
}
return IO.of(content);
}
public static IO<String> readLineFromConsole() {
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in));
String line;
try {
line = reader.readLine();
} catch (Exception e) {
line = "";
}
return IO.of(line);
}
}Editor is loading...
Leave a Comment