jdk1.6及之前版本IO流异常处理标准代码

    xiaoxiao2021-12-13  19

    public void demo() throws FileNotFoundException, IOException { // 抛出异常 FileInputStream fis = null; // 赋初值 FileOutputStream fos = null; try { fis = new FileInputStream("a.txt"); fos = new FileOutputStream("b.txt"); byte[] arr = new byte[1024*8]; // 8192Bytes是有讲究的 int len; while((len = fis.read(arr)) != -1) { fos.write(arr,0,len); } }finally { try{ // try...finally...嵌套是为了防止关闭流时出现异常 if(fis != null) fis.close(); }finally { if(fos != null) fos.close(); } } }
    转载请注明原文地址: https://ju.6miu.com/read-950285.html

    最新回复(0)