控制台输入输出+文件输入输出

①控制台输入输出

标准数据流:java.io.System

System类在main函数一开始就被加载到内存中。有InputStream in,PrintStream out,PrintStream err 三个静态内部变量。

===>Scanner,new BufferedReader(InputStreamReader)

②文件输入输出

五个基本类 :File+ InputStream/outputStream/Reader/Writer +Buffer



==>FileInputStream :read()

​		 ==>BufferedInputStream:

==>FileOutputStream: write() 

​		==>BufferedOutputStream

==>FileReader: read()

​		==>BufferedReader:readLine(字符串,读完为null)

==>FileWriter: write()

​		==>BufferedWriter: newLine(),flush(),write(字符串)

例子:字节流复制文件

import java.io.*;
public class copyMP4{
	public static void main(String[] args) throws IOException {
		long start=System.currentTimeMillis();
		
//		BufferedInputStream bis=new BufferedInputStream(new FileInputStream("F:\\videos\\1.mp4"));
//		BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("F:\\videos\\1cp.mp4"));//59毫秒

		FileInputStream fis=new FileInputStream("F:\\videos\\1.mp4");
		FileOutputStream fos=new FileOutputStream("F:\\videos\\1cpcp.mp4");//349
		
		byte[] bytes=new byte[1024];
		int len;
		while((len=fis.read(bytes))!=-1) fos.write(bytes,0,len);
		
		fis.close();
		fos.close();
		
		long end=System.currentTimeMillis();
		System.out.println(end-start);
	}
}
posted @ 2021-09-19 23:00  zhuangzhongxu  阅读(55)  评论(0编辑  收藏  举报