You can use System.in
to read from the standard input. It works just like entering it from a keyboard. The OS handles going from file to standard input.
import java.util.Scanner; class MyProg { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Printing the file passed in:"); while(sc.hasNextLine()) System.out.println(sc.nextLine()); } }
Related Posts:
- What is EOF in the C programming language?
- Why am I getting InputMismatchException?
- Getting Keyboard Input
- How to read groups of integers from a file, line by line in C++
- What does Scanner input = new Scanner(System.in) actually mean?
- What does Scanner input = new Scanner(System.in) actually mean?
- java.util.NoSuchElementException – Scanner reading user input
- How would I use a while loop to keep requesting user input
- How do I check if the user is pressing a key?
- C++ – pointer being freed was not allocated error
- Using a do-while loop to check a User’s input in Java
- Resource leak: ‘in’ is never closed
- How to use redirection in C for file input
- Frontend Category Checkbox
- Input with pattern not working
- Initialization of an ArrayList in one line
- What does the “+=” operator do in Java?
- Is there a Heap in java?
- What’s the difference between map() and flatMap() methods in Java 8?
- Why do we need copy constructor and when should we use copy constructor in java
- What are the -Xms and -Xmx parameters when starting JVM?
- How to match “any character” in regular expression?
- Exception in thread “main” java.lang.Error: Unresolved compilation problems
- Error java.lang.OutOfMemoryError: GC overhead limit exceeded
- and in Java – why it works this way?
- Non-static variable cannot be referenced from a static context
- JAVA invalid maximum heap size. The specified size exceeds the maximum representable size
- JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemState
- How to encrypt String in Java
- A long bigger than Long.MAX_VALUE
- Unreported exception java.lang.Exception; must be caught or declared to be thrown
- How to clear the console?
- How to capitalize the first letter of a String in Java?
- Scanner vs. BufferedReader
- Control an Arduino with Java
- Meaning of *= in Java
- Raw use of parameterized class
- :: (double colon) operator in Java 8
- What does ‘0’ do in Java?
- Simple Java 2D graphics: draw a rectangle?
- How to solve error: ‘;’ expected in Java?
- Making a Java Makefile
- Censored Words Condition
- method in class cannot be applied to given types
- unused import statement for used ones in IntelliJ IDEA
- Unsigned long in Java
- Integer range when using 64bit jdk
- Removing whitespace from strings in Java
- what is this ANT build?
- org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
- How can I avoid this Ant Build error?
- Java Comparator class to sort arrays
- (The Triangle class) Design a class named Triangle that extends GeometricObject
- Cannot assign requested address using ServerSocket.socketBind
- Consider defining a bean of type ‘package’ in your configuration [Spring-Boot]
- Java – How to do floor division?
- Short form for Java if statement
- How to read json file into java with simple JSON library
- How can I convert a long to int in Java?
- Is there a difference between x++ and ++x in java?
- org.apache.jasper.JasperException: Unable to compile class for JSP:
- Drawing Hexagon Using Java error
- How do I parse command line arguments in Java?
- Missing method body, or declare abstract in Java
- java code is showing error. ( ‘;’,expected)
- Efficient swapping of elements of an array in Java
- hibernate properties not found
- Make a simple timer in Java
- How to switch scenes in JavaFX
- Corrupt jar file
- ReferenceError: “alert” is not defined
- How to write an ArrayList of Strings into a text file?
- Aspect Ratio with 800×480
- How do I convert a String to a BigInteger?
- How to set JAVA_HOME in Linux for all users
- What is ‘PermSize’ in Java?
- Jackson with JSON: Unrecognized field, not marked as ignorable
- Create a two dimensional string array anArray[2][2]
- Convert double to Int, rounded down
- A beginner’s error (args[0]) [duplicate]
- Converting from byte to int in Java
- how to set default main class in java?
- Is there a way to end the program if statement is false?
- ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”
- convert string to arraylist
in java - Java: Not a statement
- how to use drawArc()
- How to add RGB values into setColor() in Java?
- Can you write virtual functions / methods in Java?
- Creating video player using Java
- Can I override and overload static methods in Java?
- How can i fix this equals on primitive type(int)
- Java: Variable is already defined in method
- Get data from dropdown and update page
- Save and user submitted data from a form and display them in the wp backend
- How to add “on change” to a text input in contact form7?
- Desktop is class List and Mobile is class Grid
- Shortcodes in billing fields doesn’t work
- How to call or add password input / generate password / password strenght meter in custom registration form?
- Name Input from widget displays Sidebar name instead of saved data