java常用类之——java.util.Scanner

package com.niu.demo;

import java.util.Scanner;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.io.IOException;

public class Scanner_{
	
	public static void main(String[] args){
		
		//从控制台读
		Scanner in = new Scanner(System.in);	
		while(!in.hasNextInt()){	
			System.out.println(in.nextLine());
		}
		
		//从文档读
		Path p = Paths.get("Scanner_.java");
		try{
			Scanner Fin = new Scanner(p);
			while(Fin.hasNext()){
				System.out.println(Fin.nextLine());
			}
		}catch(IOException msg){
			System.out.println(msg.toString());
		}finally{
			System.out.println("todo:// close");
		}
	}
}

你可能感兴趣的:(java,scaner,读文件,控制台,path)