我的代码里
byte[] filecontent = decoder.decodeBuffer(body);解码出一个byte[],这个是个文件类型,我想转化回去File应该怎么做啊
File testFile = new File(filecontent....);
诸如此类的 谢谢
------解决方案--------------------
应该不可以吧,File类没有这么的构造函数(这个你可以参考JDOC或API或源代码),我看过是没有这样的构造函数的
不过你可以类似下面这样先建一个,然后把你的bytes写进去,用完后再删掉
- Java code
byte[] byteArray={0x59,0x34,0x45}; File f = new File("temp.te"); if(!f.exists()) { try { f.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } FileOutputStream fos; try { fos = new FileOutputStream(f); fos.write(byteArray); fos.close(); //do something you want; f.delete();//delete it after using it } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
------解决方案--------------------
------解决方案--------------------
楼主到底要保存什么呢?
一直没搞明白
要不你就ObjectInputStream/ObjectOutputStream
按对象序列化来