Untitled

 avatar
Anonymous
java
09/21/2025 7:00 PM
1000 B
22
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