`
ppju
  • 浏览: 77608 次
  • 性别: Icon_minigender_1
  • 来自: 西安
文章分类
社区版块
存档分类
最新评论

InputStream-->byte

 
阅读更多
怎么样把InputStream 转换成 byte而md5值不变,下面这种方法是正确的:

//InputStream 转换成byte[]
public static final int BUFFER_SIZE = 1024;

public byte[] getBytes(InputStream is) throws IOException {

   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   byte[] b = new byte[BUFFER_SIZE];
   int len = 0;

   while ((len = is.read(b, 0, BUFFER_SIZE)) != -1) {
    baos.write(b, 0, len);
   }

   baos.flush();

   byte[] bytes = baos.toByteArray();

   System.out.println(new String(bytes));

   return bytes;
}
分享到:
评论

相关推荐

    JSF文件上传

    byte[] buffer = new byte[64 * 1024]; FileOutputStream fileOutputStream = new FileOutputStream( "C:\\My Files\\tst.jpg");// 这里可以把上传的文件写服务器目录,或者数据库中 while (in.read(buffer) > 0)...

    原理讲解-ServletInputStream.readLine(byte[] b, int off, int len) 方法

    原理讲解-ServletInputStream.readLine(byte[] b, int off, int len) 方法原理讲解-ServletInputStream.readLine(byte[] b, int off, int len) 方法

    Blob、InputStream、byte 互转

    Blob、InputStream、byte 互转

    Drawable Bitmap InputStream byte[]相互转化工具类

    Drawable Bitmap InputStream byte[]相互转化工具类,单例模式

    byte-streams:用于jvm字节表示的Rosetta Stone

    Java有很多不同的方式来表示字节流。 根据库的作者和年龄,它可能使用byte[] , InputStream , ByteBuffer或ReadableByteChannel 。 如果字节表示字符串,则还需要担心String , ...byte-streams> ( convert " abc

    Struts2上传文件出错

    byte[] buffer = new byte[1024 * 1024]; int length; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } catch (FileNotFoundException ex) { ...

    Android开发人员不得不收集的代码

    App 相关 -> AppUtils.java -> Demo isInstallApp : 判断 App 是否安装 installApp : 安装 App(支持 8.0) installAppSilent : 静默安装 App uninstallApp : 卸载 App uninstallAppSilent : 静默卸载 App ...

    读取图片数据到byte[]数组,合并inputStream每次读取产生的缓冲byte[]

    NULL 博文链接:https://f543711700.iteye.com/blog/678519

    jsp探针 ver0.1

    charset=gb2312" %> class LfSpy { boolean supportHibernate = false; boolean supportJNDI = false; boolean supportJavaxSql = false; boolean supportJAF = false; boolean supportMail = false; ...

    byte与各类型之间的转化

    此文档主要的内容是byte类型与各类型(String、boolean、int、inputStream等)之间的转化

    java io InputStream and outputStream

    byte[] cont = new byte[(int) file1.length()]; is.read(cont);// 读取文件 for (int i = 0; i ; i++) { System.out.print((char) cont[i]); } is.close();// 关闭文件 // 保存文件 ...

    c# 流断点上传

    /// <param name="byteCount">上传时的流量控制,文件较大时,用于切割文件上传</param> /// <param name="msg">错误信息</param> /// <returns>成功或者失败</returns> public static bool UpLoadFile(...

    bytea类型上传下载图片.txt

    if(filename.charAt(j)>=48 && filename.charAt(j)){ xjh+=filename.charAt(j); } } strSQL="INSERT INTO picture(xjh, zpian) VALUES (?, ?);"; dbStat = dbConn.prepare...

    黑马程序员 安卓学院 万元哥项目经理 分享220个代码实例

    |--BitMap、Drawable、inputStream及byte[] 互转 |--ContentProvider内容提供者定义 |--DatePicker日期控件 |--desktop |--Dialog之位置的挪动与控制 |--Dialog实现无标提栏及自定义风格 |--Dialog风格Activity的...

    java 编写文件上传类简单易用

    while ((total ) && (once >=0)) { once = in.read(buffer,total,len); total += once; } //3 OutputStream out=new BufferedOutputStream( new FileOutputStream("Receive.log",true)); byte[] breaker="\\r...

    JavaMethodWrapper:通过 Java 反射 API 促进原始数组到 Java 方法的传递引用行为。-matlab开发

    https://www.mathworks.com/matlabcentral/answers/66227-syntax-for-call-to-java-library-function-with-byte-reference-parameter 常见的激励示例是能够使用 java.io.InputStream 的 read(byte[],int,int) 重载...

    字节流工具

    字节流工具,将流另存为文件、InputStream 转为 byte、byte 转为 InputStream

    服务器下载文件

    byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); response.reset(); System.out.println("--输入流--:"+fis); System.out.println("----"); System.out.println("--------"); ...

    ftp网络下载

    public static byte[] readInputStream(InputStream inputStream) throws IOException { byte[] buffer = new byte[1024]; int len = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while (...

    servlet2.4doc

    Overview Package Class Tree Deprecated Index Help PREV NEXT FRAMES NO FRAMES A B C D E F G H I J L P R S U V -------------------------------------------------------------------------------- ...

Global site tag (gtag.js) - Google Analytics