@Test
void closeIOTest() {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream("123.png"));
bos = new BufferedOutputStream(new FileOutputStream("321.png"));
byte[] cache = new byte[1024];
int i = -1;
while ((i = bis.read(cache)) != -1) {
bos.write(cache);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(bis);
IOUtils.closeQuietly(bos);
}
}
@Test
void InputStreamIOTest() {
BufferedInputStream bis = null;
try {
bis = new BufferedInputStream(new FileInputStream("关雎.txt"));
byte[] cache = new byte[1024];
int i = -1;
while ((i = bis.read(cache)) != -1) {
System.out.println(new String(cache,"UTF-8"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(bis);
}
}
BufferedInputStream练习
最新推荐文章于 2024-08-18 21:36:31 发布