FileOperateUtil fpu=
new FileOperateUtil(); publicstatic FileOperateUtil getInstance(){ return fpu; } publicbyte[] getBytes(File file){ byte[] buffer =
null; try { FileInputStream fis=
new FileInputStream(file); ByteArrayOutputStream bos=
newByteArrayOutputStream(1000
); byte[] b =
newbyte[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; } publicString writeFileToService(
byte[] bt, String filePath,String fileName) { BufferedOutputStream bos=
null; FileOutputStream fos=
null; File file=
null; try { File dir=
new File(filePath); System.out.println(dir.exists()); if(!dir.exists()){
//判断文件目录是否存在 dir.mkdirs(); } file=
newFile(filePath+"\\"+
fileName); fos=
new FileOutputStream(file); bos=
new BufferedOutputStream(fos); bos.write(bt); } 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(); } } } returnfilePath+"\\"+
fileName; } }来源: http://www.bubuko.com/infodetail-2011966.html