JAVA IO - BufferReader的應用

import java.io.BufferedReader;
import java.io.FileReader;

public class BufferedReaderTest {
	public static void main(String args[]) {
//		try {
//			BufferedReader reader = new BufferedReader(new FileReader(
//					"C:\\workspace\\Test\\JavaIO\\src\\BufferedReaderTest.java"));
//			String line = "";
//			while((line = reader.readLine()) != null){
//				System.out.println(line);
//			}
//			reader.close();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
		
		try(BufferedReader reader = new BufferedReader(new FileReader(
				"C:\\workspace\\Test\\JavaIO\\src\\BufferedReaderTest.java"))) {
			
			String line = "";
			while((line = reader.readLine()) != null){
				System.out.println(line);
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
相關文章
相關標籤/搜索