zoukankan      html  css  js  c++  java
  • 文件和字节数组的相互转换

    package com.daxin.miaozhen;
    
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    /**
     * 
     * @author daxin
     * 
     * @email leodaxin@163com
     * 
     * @date 2017年9月14日 下午10:23:07
     * 
     */
    public class MainByte {
        public static void main(String[] args) throws Exception {
    
    
            byte[] bytes = file2Bytes("C:\Coding\miaozhen\src\com\daxin\miaozhen\StringDemo.java");
            byte2File(bytes);
            System.out.println(bytes.length);
    
        }
    
        public static byte[] file2Bytes(String path) throws Exception {
            File file = new File(path);
            BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
            ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
            byte[] buffer = new byte[1024];
            int length = 0;
            while ((length = in.read(buffer)) != -1) {
                bos.write(buffer, 0, length);
            }
    
            byte[] data = bos.toByteArray();
            bos.close();
            bos = null;
            in.close();
            in = null;
            return data;
        }
    
        public static void byte2File(byte[] data) throws Exception {
            BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream("StringDemo1.java.txt"));
            bo.write(data);
            bo.flush();
            bo.close();
        }
    
    }
  • 相关阅读:
    11、序列比对
    10、RNA-seq for DE analysis training(Mapping to assign reads to genes)
    9、IPA通路分析相关网页教程
    3、perl进阶
    8、Transcriptome Assembly
    7、RNAseq Downstream Analysis
    Microsoft dynamic 批量更新
    c# datagridview 相关操作。
    $.ajax 提交数据到后台.
    c# Datatable
  • 原文地址:https://www.cnblogs.com/leodaxin/p/7523634.html
Copyright © 2011-2022 走看看