java按行读取文件实现方法一

public static void main(String[] args) throws IOException
	{
		
		FileInputStream inputStream = new FileInputStream("d://a.txt");
                 //设置inputStreamReader的构造方法并创建对象设置编码方式为gbk
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"gbk"));
			
		String str = null;
		while((str = bufferedReader.readLine()) != null)
		{
			System.out.println(str);
		}
			
		//close
		inputStream.close();
		bufferedReader.close();
		
	}

 

你可能感兴趣的:(java按行读取文件实现方法一)