public class T3 { public static void main(String[] args){ String filePath = "E:\\softoon\\workspace_softoon\\TestMobile\\src\\1.docx"; String outFilePath = "E:\\softoon\\workspace_softoon\\TestMobile\\src"; String outFileName = "2.docx"; getFile(getBytes(filePath),outFilePath,outFileName); } /** * 获得指定文件的byte数组 */ public static byte[] getBytes(String filePath){ byte[] buffer = null; try { File file = new File(filePath); FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream bos = new ByteArrayOutputStream(1000); byte[] b = new byte[1000]; int n; while ((n = fis.read(b)) != -1) { bos.write(b, 0, n); } fis.close(); bos.close(); buffer = bos.toByteArray(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return buffer; } /** * 根据byte数组,生成文件 */ public static void getFile(byte[] bfile, String filePath,String fileName) { BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; try { File dir = new File(filePath); if(!dir.exists()&&dir.isDirectory()){//判断文件目录是否存在 dir.mkdirs(); } file = new File(filePath+"\\"+fileName); fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); bos.write(bfile); } catch (Exception e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e1) { e1.printStackTrace(); } } } } }
=========================================================
http://forai.iteye.com/blog/1221081
相关推荐
byte数组操作的工具类,支持byte数组转int,int转byte数组,byte数组转short,short转byte数组。。。 下载的人多了,csdn会自动涨分,现在可以手动调了,我给降到最低了
今天小编就为大家分享一篇java中两个byte数组实现合并的示例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
java基本类型与byte数组互相转换.pdf
Java bytes数组与基本类型的相互转换 Int -> Bytes int64ToByte8 int48ToByte6 int40ToByte5 int32ToByte4 int24ToByte3 int16ToByte2 int8ToByte Bytes -> Int bytesToInt64 bytesToInt48 bytesToInt40 bytesTo...
char short int long float double 转换成byte数组
主要整理了Java中byte数组与其他基本类型的转换
ip地址转4字节byte,char转2字节byte,byte数组转char,int整数转换为4字节的byte数组,byte数组转换为int整数,double类型转8字节数组,8位数组转double,long整数转换为8字节的byte数组,short整数转换为2字节的...
做Java课程设计有用到的例子,是个看了就能上手的例子。
Java-byte数组转换成16进制字符串
将Image数据转换为byte数组,便于网络图片传输
java基本类型与byte数组互相转换
主要介绍了java整数与byte数组的转换实现代码的相关资料,需要的朋友可以参考下
主要给大家介绍了关于Java任意长度byte数组转换为int数组的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者使用Java具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
写一个方法,将int类型转换为字节数组,输入任意int类型整型,输出字节数组;写第二个方法,输入字节数组,输出对应int类型数据。
java基本类型与byte数组互相转换.doc
java工具类 : string转10进制sacii byte数组、 10进制sacii byte数组转16进制字符数组、 16进制字符数组转16进制byte数组、 string与BCD互转等方法,包含多个转换方法, 足够满足日常解包组包需求
java基本类型与byte数组互相转换.rar
下面小编就为大家带来一篇基于java中byte数组与int类型的转换(两种方法)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
java基本类型与byte数组互相转换文.pdf