Let’s say I have theese words in a text file
Dictionary.txt
artificial
intelligence
abbreviation
hybrid
hysteresis
illuminance
identity
inaccuracy
impedance
impenetrable
imperfection
impossible
independent
How can I make each word a different object and print them on the console?
3
Answers
You can simple use
Scanner.nextLine();
function.Here is the following code which can help
also import the libraries
Use following code:-
You must go and research on
Scanner
classThis is a very simple solution using
Files
:Source: https://kodejava.org/how-do-i-read-all-lines-from-a-file/
This is another neat solution using buffered reader:
Source: https://javarevisited.blogspot.com/2012/07/read-file-line-by-line-java-example-scanner.html#axzz7lrQcYlyy
These are all good answers. The OP didn’t state what release of Java they require, but in modern Java I’d just use: