Scanner实现对文件的操作

来源:互联网 发布:淘宝买家隐藏评论 编辑:程序博客网 时间:2024/06/08 23:58
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


/**
 * 实现一个对文件操作
 * @author  caowh
 * E-mail: 458584881@qq.com
 * @date 创建时间:2017年5月3日 下午11:26:23
 */
public class ScannerFileDemo {


public static void main(String[] args) throws FileNotFoundException {
//创建一个输入对象实现对文件的操作
Scanner scanner = new Scanner(new File("d:"+File.separator+"test.txt"));
System.out.println("test.txt文件内容如下:");
while(scanner.hasNextLine()){
System.out.println(scanner.nextLine());
}
}
}
0 0