您的位置:首页 > 编程语言 > Java开发

Java快速从一个文件夹复制到另外一个文件夹

2015-10-23 13:39 441 查看
try {
				BufferedInputStream in = new BufferedInputStream(
						new FileInputStream(srcPath), STREAM_SIZE);
				ByteArrayOutputStream out = new ByteArrayOutputStream(
						STREAM_SIZE);
				OutputStream oos = new FileOutputStream(destPath);
				System.out.println(srcPath);
				int size = 0;

				byte[] temp = new byte[STREAM_SIZE];

				
				while ((size = in.read(temp)) != -1) {

					out.write(temp, 0, size);
					// 缓冲输出流的缓冲区大于10M时写入输出流然后清空缓冲区
					if (out.size() > STREAM_SIZE * 10) {
						// 缓冲流中的数据写入输出流
						out.writeTo(oos);
						// 清空缓冲输出流
						out.reset();
					}
				}
				out.writeTo(oos);
				in.close();

			} catch (IOException e) {
				System.out.println(e.toString());
			}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: