简述:
常用文件流格式,供备忘
urlDownload = new URL("http://localhost:8080/Server/fetch?id=" + id);
HttpURLConnection connection = (HttpURLConnection)urlDownload.openConnection();
connection.connect();
InputStream is = connection.getInputStream();
String filePath = "E:\\temp";
if( !new File(filePath).exists()){
new File(filePath).mkdirs();
}
final File srcFile = new File(filePath + File.separatorChar
+ UUID.randomUUID().toString().replace("-", "") + ".jpg");
FileOutputStream fos = new FileOutputStream(srcFile);
// bufImg = ImageIO.read(is);
byte[] bytes = new byte[1024];
int len = 0;
while((len = is.read(bytes)) != -1){
fos.write(bytes);
}
fos.flush();
fos.close();
is.close();
String filePath = "E:\\temp";
if( !new File(filePath).exists()){
new File(filePath).mkdirs();
}
final File srcFile = new File(filePath + File.separatorChar
+ UUID.randomUUID().toString().replace("-", "") + ".jpg");
FileOutputStream fos;
try {
fos = new FileOutputStream(srcFile);
fos.write(img_expected_0);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}