54、java 输入流转文件
/**
* 流转换成文件
* @param inputStream
*/
public void inputStreamToFile(InputStream inputStream,String filename){
try{
//新建文件
File file = new File("路径");
if (file.exists()){
file.createNewFile();
}
OutputStream os = new FileOutputStream(file);
int read = 0;
byte[] bytes = new byte[1024 * 1024];
//先读后写
while ((read = inputStream.read(bytes)) > 0){
byte[] wBytes = new byte[read];
System.arraycopy(bytes, 0, wBytes, 0, read);
os.write(wBytes);
}
os.flush();
os.close();
inputStream.close();
}catch (Exception e){
e.printStackTrace();
}