InputStream转换为File

InputStream ins = (new AnnexXML()).getClass().getResourceAsStream("../../annexInternet.xml");
   File f=new File("annexInternet.xml");

 inputstreamtofile(ins, f);

public static void inputstreamtofile(InputStream ins,File file) {
  try {
   OutputStream os = new FileOutputStream(file);
   int bytesRead = 0;
   byte[] buffer = new byte[8192];
   while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
    os.write(buffer, 0, bytesRead);
   }
   os.close();
   ins.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

猜你喜欢

转载自lspgdut.iteye.com/blog/1066517