文件拷贝Demo

private static void copy(InputStream is, OutputStream os) {
is = new BufferedInputStream(is);
os = new BufferedOutputStream(os);
try {
byte[] b = new byte[1024];
do {
int size = is.read(b);
if (size == 0) {
Thread.yield();
continue;
} else if (size < 0) {
break;
}
os.write(b, 0, size);

} while (true);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

posted @ 2020-04-02 14:50  工设091  阅读(130)  评论(0)    收藏  举报