1.注意Scanner的用法,使用new时候Scanner的构造方法有两种,+Scanner(sourse:file)和+Scanner(sourse:String),比如写Scanner a = new Scanner("java.txt");会从字符串“java.txt”中读取。
public class ClassOne { public static void main(String[] args) throws Exception { File b = new File("java.txt"); Scanner a = new Scanner(b); System.out.println(a.nextLine()); } }
所以要是想从文件中读取,要先new一个File b;
时间: 2024-12-22 14:29:44