博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
从文本文件逐行读入数据
阅读量:4625 次
发布时间:2019-06-09

本文共 856 字,大约阅读时间需要 2 分钟。

从.txt文档逐行读入数据,用到FileReader和BufferedReader类:

import java.io.IOException;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.BufferedReader;public class ReadLine_Test {	public static void main(String[] args) throws IOException{		String FilePath = "e:/data.txt";		FileReader fr = new FileReader(FilePath); //建立FileReader对象,并实例化为fr		BufferedReader br = new BufferedReader(fr); //建立BufferedReader对象,并实例化为br		StringBuffer sBuffer = new StringBuffer();		String Line = br.readLine();   //从文本中读取一行字符串				int i = 1;		while(Line != null){			System.out.println("Line"+i+":"+Line);			sBuffer.append(Line);			sBuffer.append("\n");			Line = br.readLine();   //从文本中继续读取一行字符串			i = i+1;		}				if(br != null){			br.close();   //关闭BufferedReader对象		}		if(fr != null){			fr.close();   //关闭文件		}	}}

转载于:https://www.cnblogs.com/DianaCody/p/5425673.html

你可能感兴趣的文章
linux下shellcode编写入门
查看>>
selenium入门环境之浏览器问题
查看>>
BA--三相异步电机_星三角降压启动
查看>>
VM虚拟机安装后的网络设置
查看>>
jQuery Alert Dialogs (Alert, Confirm, & Prompt代替方案)
查看>>
牛客 109 C 操作数 (组合数学)
查看>>
Linux下通过 rm -f 删除大量文件时报错:Argument list too long
查看>>
【2019/2/1】安卓应用——记账本,学习记录【1】
查看>>
记因PHP的内存溢出导致的事故之解决
查看>>
[转]Apache commons 工具包应用
查看>>
Bridge模式——设计模式学习笔记
查看>>
【python】统一转换日期格式dateutil.parser.parse
查看>>
spring的依赖注入
查看>>
CF 576A 猜数
查看>>
『重构--改善既有代码的设计』读书笔记----代码坏味道【3】
查看>>
ABAP 中JSON格式的转换与解析
查看>>
使用oschina的gitserver
查看>>
嵌入式课程学习大纲分享,零基础入门嵌入式技术
查看>>
Could not get the value for parameter encoding for plugin execution default- resources
查看>>
Android 网络通信之Socket
查看>>