1. 程式人生 > >java按行讀取檔案實現方法一

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();
		
	}