public static voidmain(String[] args) throws Exception { // 定义字节缓冲输入流 BufferedInputStream bis = null; // 定义字节缓冲输出流 BufferedOutputStream bos = null; try { bis = new BufferedInputStream(newFileInputStream("d://readme.txt")); bos = new BufferedOutputStream(newFileOutputStream("d://readme.txt.byte")); byte[] bys = new byte[1024]; int len = -1; while ((len = bis.read(bys)) != -1) { bos.write(bys, 0, len); bos.flush(); } } catch(Exception e) { e.printStackTrace(); } finally { if (bis != null) { try { bis.close(); } catch (Exception e) { e.printStackTrace(); } } if (bos != null) { try { bos.close(); } catch (Exception e) { e.printStackTrace(); } } } }
|