`

IO 学习

    博客分类:
  • java
 
阅读更多

 

附件是学习IO的一些总结,当然还不全面需要继续总结。

 

 

public class Test1 {
	public static void main(String[] args) {
		try {
			FileReader fr = new FileReader("F:\\sysmodel.xml");
			BufferedReader br  = new BufferedReader(fr);
			char[] cs = new char[1024];
			int len=0 ; 
			int cha ; 
			String strLine ; 
			long start = System.currentTimeMillis();
			//一次读取一个字符列表 ,读取数据尽量选用这个
			while( (len = fr.read(cs, 0, 1024))!=-1 ){
				System.out.println(new String( cs,0,len) );
			}
//			//一次只读取一个字符
//			while((cha = fr.read())!=-1 ){
//				System.out.println( (char)cha);
//			}
			
			while((strLine = br.readLine())!=null ){
				System.out.println( strLine );
			}
			
			long end = System.currentTimeMillis();
			System.out.println( start  - end );
			fr.close();
				
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics