zoukankan      html  css  js  c++  java
  • java中i/o练习

    总结:

    FileInputStream fis;

    int length;

    while((length=fis.read(b,0,b.length))!=-1){

      output.write(b,0,length);

    }

    }

    catch(){

    }finally{

    if(fis!=null) fis.close();

    if(output!=null) output.close();

    }

    return output.toByteArray();

    package com.aini;
    
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.*;
    
    ////使用FileInputStream读取文件信息 
    public class rt {
    	public static byte[] getByte(File file) throws Exception {
    		FileInputStream fis = null;
    		ByteArrayOutputStream fd = new ByteArrayOutputStream();
    		try {
    			fis = new FileInputStream(file); // 写入文件
    			byte[] b = new byte[6];
    			int i;
    			while ((i = fis.read(b, 0, b.length)) != -1) {
    				fd.write(b, 0, i);
    			}
    
    		} catch (Exception E) {
    			System.out.println("Error occur during " + file.getAbsoluteFile());
    		} finally {
    			if (fis != null)
    				fis.close();
    			if (fd != null)
    				fd.close();
    		}
    		return fd.toByteArray();// 最后一步返回
    
    	}
    }
    

      

  • 相关阅读:
    day63_django_html
    day62_django
    day20
    diango_自定义标签问题
    day64_django_orm
    day16_函数嵌套及对象
    day60_django
    pip 安装问题
    day13_文件操作
    文本溢出显示省略号(…) 小坦克
  • 原文地址:https://www.cnblogs.com/langlove/p/3417123.html
Copyright © 2011-2022 走看看