|
@@ -247,57 +247,6 @@ public class AttachmentFileUtil {
|
|
|
return attObj;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 根据地址获得数据的字节流并转换成大小
|
|
|
- * @param strUrl 网络连接地址
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static int getFileSizeByUrl(String strUrl){
|
|
|
- InputStream inStream=null;
|
|
|
- ByteArrayOutputStream outStream=null;
|
|
|
- int size = 0;
|
|
|
- try {
|
|
|
- URL url = new URL(strUrl);
|
|
|
- HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
|
|
- conn.setRequestMethod("GET");
|
|
|
- conn.setConnectTimeout(5 * 1000);
|
|
|
- inStream = conn.getInputStream();
|
|
|
-
|
|
|
- outStream = new ByteArrayOutputStream();
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
- int len = 0;
|
|
|
- while( (len=inStream.read(buffer)) != -1 ){
|
|
|
- outStream.write(buffer, 0, len);
|
|
|
- }
|
|
|
- byte[] bt = outStream.toByteArray();
|
|
|
-
|
|
|
- if(null != bt && bt.length > 0){
|
|
|
- DecimalFormat df = new DecimalFormat("#");
|
|
|
- size = Integer.parseInt(df.format((double) bt.length));
|
|
|
-
|
|
|
- System.out.println("文件大小=:" + size);
|
|
|
- }else{
|
|
|
- System.out.println("没有从该连接获得内容");
|
|
|
- }
|
|
|
- inStream.close();
|
|
|
- outStream.close();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }finally{
|
|
|
- try{
|
|
|
- if(inStream !=null){
|
|
|
- inStream.close();
|
|
|
- }
|
|
|
- if(outStream !=null){
|
|
|
- outStream.close();
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- return size;
|
|
|
- }
|
|
|
-
|
|
|
private static InputStream getInputStreamFromURL(String urlString) throws IOException {
|
|
|
URL url = null;
|
|
|
try {
|