java io流实现拷贝文件

public void test4() throws Exception {
		// 1:读取文件
		InputStream in = new FileInputStream("e:/dmx1.mp4");
		// 2:写一个文件
		OutputStream out = new FileOutputStream("d:/a/a.mp4");
		// 3:开始读写文件
		byte[] bs = new byte[1024];  //一次文件中读取1024个字节,如果文件中少于1024个字节,则就读取<1024节字,返回读取到的节的数量,如果文件中大于1024个字节
		int len = 0;
		while ((len = in.read(bs)) != -1) {
			out.write(bs, 0, len);
		}
		in.close();
		out.close();
	}

猜你喜欢

转载自blog.csdn.net/qq_33160365/article/details/79604207