FastIO is a robust, efficient, and versatile Java library designed to replace the standard Scanner class for handling user input. It offers significant advantages in terms of performance, error handling, and flexibility, especially when dealing with large inputs or complex data formats.
-
Clone or download the
FastIO.javafile from this repository. -
Add the
FastIO.javafile to your Java project. -
Create an Object from this Code :
FastIO <object-name> = new FastIO();
↑ - This allows you to access the non-static methods only!
-
Assuming sc is the object, the following methods are available:
- sc.next() -> Reads the next token as String
- sc.nextLine() -> Reads the next line as String
- sc.nextInt() -> Reads the next token as int
- sc.nextLong() -> Reads the next token as long
- sc.nextDouble() -> Reads the next token as double
- sc.nextFloat() -> Reads the next token as float
- sc.nextBoolean() -> Reads the next token as boolean
- sc.nextShort() -> Reads the next token as short
- sc.nextByte() -> Reads the next token as byte
- sc.nextChar() -> Reads the first character of the next token
- sc.hasNext() -> Checks if another token is available
- sc.nextIntArray(n) -> Reads n integers into an int[]
- sc.nextLongArray(n) -> Reads n longs into a long[]
- sc.nextDoubleArray(n) -> Reads n doubles into a double[]
- sc.nextStringArray(n) -> Reads n tokens into a String[]
- sc.nextIntMatrix(r, c) -> Reads r x c integers into int[][]
- sc.nextDoubleMatrix(r, c) -> Reads r x c doubles into double[][]
- sc.nextStringList() -> Reads all remaining tokens in the current line as List
- sc.nextStringListLine() -> Reads all tokens from the current/new line as List
- sc.skipLines(n) -> Skips n lines
- sc.readAllLines() -> Reads all lines as List
- sc.readUntil(delim) -> Reads tokens until delim is found (not included)
- sc.peek() -> Peeks at the next token without consuming it
- sc.readAllInts() -> Reads all remaining tokens as List
- sc.readAllDoubles() -> Reads all remaining tokens as List
- sc.readAllLongs() -> Reads all remaining tokens as List
- sc.readAllStrings() -> Reads all remaining tokens as List
- sc.close() -> Closes the input reader
-
Static Methods that are also available [no object needed] :
- FastIO.fromFile(path) -> Creates OpenScan from file
- FastIO.fromString(str) -> Creates OpenScan from string
- Enhanced Performance:
- Leverages
BufferedReaderfor efficient line-by-line reading. - Uses buffering to reduce the number of physical read operations, resulting in faster I/O.
- Leverages
- Line-Oriented Input:
nextLine()method efficiently reads entire lines, unlikeScanner's token-based approach.
- Robust Error Handling:
- Explicitly throws
NoSuchElementExceptionwhen input is exhausted. - Throws
NumberFormatExceptionfor invalid numeric input. - Throws
RuntimeException(wrappingIOException) for I/O errors. - Handles empty tokens when
nextChar()is called.
- Explicitly throws
- Automatic Resource Management:
- Implements
AutoCloseable, allowing for use with try-with-resources, ensuring proper resource cleanup.
- Implements
- Comprehensive Data Type Support:
- Directly reads various data types:
int,long,double,float,boolean,char,short,byte.
- Directly reads various data types:
- Flexible Array, Matrix, and List Reading:
nextIntArray(n),nextLongArray(n),nextDoubleArray(n),nextStringArray(n)read multiple values into arrays.nextIntMatrix(r, c),nextDoubleMatrix(r, c)read 2D arrays (matrices) of input.nextStringList()reads all tokens on the current line into aList<String>.nextStringListLine()reads all tokens from the current or new line as aList<String>.readAllLines()reads all lines asList<String>.
- Complete Data Loading:
readAllInts(),readAllDoubles(),readAllLongs(),readAllStrings()read all available data from the input stream.
- Input Control:
skipLines(n)efficiently skips over unwanted lines of input.readUntil(delim)reads tokens until a delimiter is found.
- Peeking and Tokenizer Control:
peek()allows peeking at the next token without consuming it.nextLine()method clears the tokenizer by assigning null.
- Robust Checking:
hasNext()method checks properly if a new token is available.
- Detailed Exception Handling:
- Handles all exceptions clearly.
Please be aware: There are fraudulent repositories on GitHub that are cloning this project's name and using AI-generated readmes, but they contain completely random and unrelated files in each release. These are NOT official versions of this project.
ALWAYS ensure you are downloading or cloning this project ONLY from its official and legitimate source:
https://github.com/Chill-Astro/FastIO?target=https://github.com
I am trying my best to report these people.
// Will add Forked Repos which are genuinely good. 🤩 I will list everything Good about them.
// Will add Inactive Forks. Uh yeah that's it atleast it's Forking not Cloning! 😅
// Includes Clones who are working against the MIT Licence and Distributing Malware. All Flaws are mentioned. 😑
Caution
MALWARE ALERT: If your downloaded folder looks like the images below, DO NOT OPEN any files. Format the drive or delete the folder immediately. Official releases are ONLY .java files or an Inno Setup .exe.
View Details
- Suspicious Windows Executables: Files ending in
.exe,.bat, or.dll(e.g.,luau.exe,StartApp.bat). - Compressed Archives: This project is distributed as an JAVA, never as a
.zipor.7zcontaining Windows binaries. - Hidden Scripts: Text files like
asm.txtused to execute malicious code on your PC. - The Following Folder Structure is used by Malware (Shown in a VM) :
Appreciate my effort? Why not leave a Star ⭐ ! Also if forked, please credit me for my effort and thanks if you do! :)


