Java io流按行读取文件

 package test.ioFile; 
  


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;


public class ReadFile {


public static final String FILE_SEPARATOR = System.getProperties()
.getProperty("file.separator");
public static String FILE_CODE = "UTF-8";
private static FileInputStream fileInputStream = null;
private static InputStreamReader inputStreamReader = null;
private static File file = null;
/**
* 常用信息放入到内存
*/
private static Map map = new HashMap();

public static void main(String[] args) {


/* 读取数据 */
try {
file = new File("D:" + FILE_SEPARATOR + "test" + FILE_SEPARATOR
+ "nn20170727.log");
fileInputStream = new FileInputStream(file);


inputStreamReader = new InputStreamReader(fileInputStream,
FILE_CODE);
BufferedReader br = new BufferedReader(inputStreamReader,
60 * 1024 * 1024);
String lineTxt = null;
while ((lineTxt = br.readLine()) != null) {
System.out.println("line -----------------");
String[] names = lineTxt.replaceAll(" +", " ").split(" ");
for (String name : names) {
System.out.println(name);


}
}
br.close();
} catch (Exception e) {
System.err.println("read errors :" + e);
}


}
}

你可能感兴趣的:(java,工具类总结)