Okay, so I'm trying to create a java program that will read a txt file and turn every line into a String. For example the txt file could be something like
This should be a string
This should be another string
And another string
Currently my code only allows me to turn a txt file into one string.
String Content = new Scanner(new File ("CONTENTS.txt")).useDelimeter(",").next();
System.out.println(Content);
Please read javadoc for Scanner :
Scanner scanner = new Scanner(new FileInputStream(fileName));
while(scanner.hasNextLine()) {
String line = scanner.nextLine();
// process line here..
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.