读取文件中的内容

来源:互联网 发布:影响二次销售 淘宝介入 编辑:程序博客网 时间:2024/05/29 15:42
import java.util.* ;
import java.text.* ;
import java.io.* ;
public class ScannerDemo05{
public static void main(String args[]){
File f = new File("E:" + File.separator + "test.txt") ;// 指定操作文件
Scanner scan = null ;
try{
scan = new Scanner(f) ;// 从键盘接收数据
}catch(Exception e){}
StringBuffer str = new StringBuffer() ;
while(scan.hasNext()){
str.append(scan.next()).append('\n'); // 取数据
}
System.out.println("文件内容为:" + str) ;
}
};
0 0
原创粉丝点击