当前位置: 代码迷 >> 综合 >> 文件和流的转换
  详细解决方案

文件和流的转换

热度:78   发布时间:2024-01-24 11:37:46.0

文件转换InputStream

/*** 文件转换InputStream* * @param file* @return* @throws FileNotFoundException*/public InputStream getInputStream(File file) throws FileNotFoundException {return new FileInputStream(file);}

inputStream 转file

/*** inputStream 转file* * @param is*            输入流* @param file*            输出的文件* @throws IOException*/public void getFile(InputStream is, File file) throws IOException {OutputStream os = null;try {os = new FileOutputStream(file);int len = 0;byte[] buffer = new byte[8192];while ((len = is.read(buffer)) != -1) {os.write(buffer, 0, len);}} finally {is.close();os.close();}}

 

  相关解决方案