I advise you to go with Scanner instead of DataInputStream. Scanner is specifically designed for this purpose and introduced in Java 5. See the following links to know how to use Scanner.

  • Java Documentation
  • Java Tutorial

Example

Scanner s = new Scanner(System.in);
System.out.println(s.nextInt());
System.out.println(s.nextInt());
System.out.println(s.next());
System.out.println(s.next());
Answer from Jomoos on Stack Overflow
๐ŸŒ
Javatpoint
javatpoint.com โ€บ java-console-readline-method
Java Console readline() Method with Examples - Javatpoint
Java Console readline() Method with Examples on java console, java tutorial, java features, methods, java math, map, string, bufferreader, java vector, java concole format(), printf(), reader(), readline(), readpassword(), writer() etc.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ io โ€บ bufferedreader_readline.htm
Java - BufferedReader readLine() method
The Java BufferedReader readLine() method read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ io โ€บ console_readline.htm
Java - Console readLine() method
package com.tutorialspoint; import java.io.Console; public class ConsoleDemo { public static void main(String[] args) { Console console = null; String name = null; try { // creates a console object console = System.console(); // if console is not null if (console != null) { // read line from the user input name = console.readLine("Name: "); // prints System.out.println("Name entered : " + name); } } catch(Exception ex) { // if any error occurs ex.printStackTrace(); } } }
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-read-file-line-by-line-in-java
How to read file line by line in Java - Javatpoint
How to read file line by line in Java with oops, string, exceptions, multithreading, collections, jdbc, rmi, fundamentals, programs, swing, javafx, io streams, networking, sockets, classes, objects etc,
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ readline() in java
readLine() in Java - Scaler Topics
August 5, 2022 - The readLine() method of BufferedReader class is used to read a one line text from a given input source for example, a file.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ io โ€บ console_readline_formatted.htm
Java - Console readLine(String fmt, Object... args) method
package com.tutorialspoint; import java.io.Console; public class ConsoleDemo { public static void main(String[] args) { Console console = null; String username = "User"; String alpha = null; try { // creates a console object console = System.console(); // if console is not null if (console != null) { // read line from the user input alpha = console.readLine("%s!
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ console-readline-method-in-java-with-examples
Console readLine() method in Java with Examples - GeeksforGeeks
June 12, 2020 - Below programs illustrate readLine() method in Console class in IO package: Program 1: ... // Java program to illustrate // Console readLine() method import java.io.*; public class GFG { public static void main(String[] args) { // Create the console object Console cnsl = System.console(); if (cnsl == null) { System.out.println( "No console available"); return; } // Read line String str = cnsl.readLine( "Enter string : "); // Print System.out.println( "You entered : " + str); } }
Find elsewhere
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ io โ€บ randomaccessfile_readline.htm
Java - RandomAccessFile readLine() method
The following example shows the usage of RandomAccessFile readLine() method. package com.tutorialspoint; import java.io.RandomAccessFile; import java.io.IOException; public class RandomAccessFileDemo { public static void main(String[] args) { try { RandomAccessFile raf = new RandomAccessFile("lines1.txt", "rw"); // Write lines to the file raf.writeBytes("Hello\n"); raf.writeBytes("World\n"); // Reset file pointer to beginning raf.seek(0); // Read lines String line1 = raf.readLine(); String line2 = raf.readLine(); System.out.println("Line 1: " + line1); // Hello System.out.println("Line 2: " + line2); // World raf.close(); } catch (IOException e) { e.printStackTrace(); } } }
๐ŸŒ
UnoGeeks
unogeeks.com โ€บ home โ€บ blog โ€บ readline java
Readline Java
December 25, 2023 - In Java, you can use the readLine() method to read input from the user from the console.
๐ŸŒ
JournalDev
journaldev.com โ€บ 709 โ€บ java-read-file-line-by-line
Java Read File: Complete Guide with Examples | DigitalOcean
February 20, 2025 - In this article, you will learn ... java.util.Scanner, Files.readAllLines(), and java.io.RandomAccessFile. You can use the readLine() method from java.io.BufferedReader to read a file line-by-line to String....
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ java-read-line
Java readLine() Method: Proper Usage Guide
February 20, 2024 - The readLine() method is then used to read a line from the file, which is printed to the console. This is a basic way to read a line in Java, but thereโ€™s much more to learn about handling different sources and advanced techniques.
๐ŸŒ
Java-samples
java-samples.com โ€บ showtutorial.php
readLine() to read strings from console input - Java samples
// A tiny editor. import java.io.*; class TinyEdit { public static void main(String args[]) throws IOException { // create a BufferedReader using System.in BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str[] = new String[100]; System.out.println("Enter lines of text."); System.out.println("Enter 'stop' to quit."); for (int i = 0; i < 100; i++) { str[i] = br.readLine(); if (str[i].equals("stop")) break; } System.out.println("\\nHere is your file:"); // display the lines for (int i = 0; i < 100; i++) { if (str[i].equals("stop")) break; System.out.println(str[i]); } } }
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 7 โ€บ docs โ€บ api โ€บ java โ€บ io โ€บ BufferedReader.html
BufferedReader (Java Platform SE 7 )
public String readLine() throws IOException ยท Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. Returns: A String containing the contents of the line, not including ...
๐ŸŒ
Quora
quora.com โ€บ What-is-readLine-in-Java
What is readLine () in Java? - Quora
Answer: The read line() method of console class is used to read a single line of text from the console. the read line represents in public string read line(). this procedure returns the string hold the line read from the console. this function is used in java program to gather input for the progr...
๐ŸŒ
California State University, Bakersfield
csub.edu โ€บ ~ychoi2 โ€บ MIS 260 โ€บ NotesJava โ€บ chap10 โ€บ ch10_13.html
readLine()
The program reads a line of character data from the keyboard by using the method readLine(), which is part of the BufferedReader object. ... It gets a line of characters, and assign them to the String inData. Then the next statement ... Enter the data: To learn Java, you must play with the programs!
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ bufferedreader-readline-method-in-java-with-examples
BufferedReader readLine() method in Java with Examples - GeeksforGeeks
May 28, 2020 - // Java program to illustrate // BufferedReader readLine() method import java.io.*; public class GFG { public static void main(String[] args) { // Read the stream 'demo.txt' // containing text // "GEEKSFORGEEKS" // "geeksforgeeks" FileReader fileReader = new FileReader( "c:/demo.txt"); // Convert fileReader to // bufferedReader BufferedReader buffReader = new BufferedReader( fileReader); while (buffReader.ready()) { System.out.println( buffReader.readLine()); } } }
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ api โ€บ java.io.bufferedreader.readline
BufferedReader.ReadLine Method (Java.IO) | Microsoft Learn
Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), a carriage return followed immediately by a line feed, or by reaching the end-of-file (EOF).