用Scanner读文本文件内容

 

 

import java.io.File;
import java.util.Scanner;

class Demo
{

    public static void main(String[] args)
    throws Exception
    {
        Scanner sc = new Scanner(new File("d:\\abc.txt"));
        System.out.println("文件内容如下:");
        while (sc.hasNextLine())
        {
            System.out.println(sc.nextLine());
        }
    }

}

 

posted @ 2018-05-28 22:43  bingxingc  阅读(725)  评论(0编辑  收藏  举报