@Test public void testCopyFile() throws Exception{ URL url = null;//把远程文件地址转换成URL格式 InputStream fin=null; FileOutputStream fileOut=null; try { url = new URL("http://ip地址/6456b1051fa6531cf9b36cacb9a0e92a.xlsx"); fin = url.openStream(); byte[] bb=steamToByte(fin); fin=byteTostream(bb); XSSFWorkbook work = new XSSFWorkbook(fin);//我的测试文件后缀为xlsx,所以用XSSF //ClassPathResource toResource = new ClassPathResource("templetes"+ File.separator); String to2Path=getClass().getClassLoader().getResource("templetes/").getPath(); //String to2Path = toResource.getPath(); fileOut=new FileOutputStream(to2Path+"888.xlsx"); work.write(fileOut); } catch (Exception e) { e.printStackTrace(); }finally { if(fin!=null){ fin.close(); } if(fileOut!=null){ fileOut.close(); } } }
java 通过网络流 把文件写到某个地方
最新推荐文章于 2023-07-17 16:52:25 发布