您的位置:首页 > 其它

IO流 不用生成文件

2015-06-29 11:02 197 查看
InputStream fin = new ByteArrayInputStream(content);

OutputStream baos = new ByteArrayOutputStream();

byte[] content = baos.toByteArray();

文件的读写

        byte[] in2b = null;

        ByteArrayOutputStream swapStream = null;

        InputStream fis = null;

        String filePath = "";

        try {

            filePath = "D://bpm.docx";

            fis = new FileInputStream(new File(filePath));

            swapStream = new ByteArrayOutputStream();

            byte[] buff = new byte[1024];

            int rc = 0;

            while ((rc = fis.read(buff, 0, 1024)) > 0) {

                swapStream.write(buff, 0, rc);

            }

            in2b = swapStream.toByteArray();

        } catch (Exception e) {

            e.printStackTrace();

        }finally{

            try {

                fis.close();

                swapStream.close();

                fis.close();

            } catch (Exception e) {

                e.printStackTrace();

            }

        }

        return in2b;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  io流