February 11, 2017

[HDGEM] How to read line with Scanner in Java

This code reads the file line by line.
public static void readFileByLine(String fileName) {    try {     File file = new File(fileName);     Scanner scanner = new Scanner(file);     while (scanner.hasNext()) {      System.out.println(scanner.next());     }     scanner.close();    } catch (FileNotFoundException e) {     e.printStackTrace();    }    }
You can also set a delimiter as a line separator and then perform the same.

Posted By Blogger to HDGEM at 2/11/2017 08:29:00 AM
Post a Comment

Featured Post

Updated Coupons / promo codes for Google Apps for Work / Business

To redeem: 1. Sign up for Google Apps   2. Go to your billing settings  3. Choose your payment plan  4. Enter your promo code ...