A replacement for java.io.Console with a System.in and System.out based fallback.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Marc Nause c161fdeb10 chore: update dependencies 4 weeks ago
badges chore(badges): remove superfluous file 4 months ago
config/checkstyle chore(checkstyle): remove rule 4 months ago
src docs(javadoc): improve comments 3 months ago
.gitignore chore(gitignore): add Eclipse files 8 months ago
CHANGELOG.md chore(changelog): add entry for next release 3 months ago
LICENSE Initial commit 3 years ago
README.md docs(readme): update version to 1.1.3 3 months ago
pom.xml chore: update dependencies 4 weeks ago


Apache 2.0 License API Reference Issue Tracker Status: Active Distribution: Maven Central

Console with Fallback

Java 1.6 introduced the java.io.Console class which provides methods to access the character-based console device, if any, associated with the current Java virtual machine.

The class has many advantages over using System.out, but unfortunately using Console in an IDE leads to ugly NullPointerExceptions (see Stackoverflow for examples). This is the reason many developers avoid Console (if they even know about the class).

Console with Fallback provides a drop-in replacement for java.io.Console which falls back to System.out and System.in in case it is used in an environment where the system does not provide a native console. It was inspired by the blog article Java: System.console(), IDEs and testing.


The Java implementation of the Console class can easily be replaced by simply replacing the imports, and the way the object is created.

Example code with Java implementation:

package de.audioattack.example;

import java.io.Console;

public class Example {

    public static void main(String... args) {
        Console console = System.console();
        console.printf("Hello world!");

Example code with Console with Fallback:

package de.audioattack.example;

import de.audioattack.io.Console;
import de.audioattack.io.ConsoleCreator;
import de.audioattack.io.ConsolePrintDecorator;

public class Example {

    public static void main(String... args) {
        Console console = ConsoleCreator.console();
        console.printf("Hello world!");

        // Use ConsolePrintDecorator for more convenient output methods.
        ConsolePrintDecorator printDecorator = new ConsolePrintDecorator(console);
        printDecorator.println("Hello world!");


The latest release is available on Maven Central.

Maven dependency:


Gradle dependency:



The API documentation can be viewed online on javadoc.io.


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.