Android 获取下载文件的真实名字
2014-09-12 00:14
471 查看
http://www.2cto.com/kf/201311/258808.html
public static String getReallyFileName(String url) { String filename = ""; URL myURL; HttpURLConnection conn = null; if (url == null || url.length() < 1) { return null; } try { myURL = new URL(url); conn = (HttpURLConnection) myURL.openConnection(); conn.connect(); conn.getResponseCode(); URL absUrl = conn.getURL();// 获得真实Url Log.e("H3c", "x:" + absUrl); // 打印输出服务器Header信息 // Map<String, List<String>> map = conn.getHeaderFields(); // for (String str : map.keySet()) { // if (str != null) { // Log.e("H3c", str + map.get(str)); // } // } filename = conn.getHeaderField("Content-Disposition");// 通过Content-Disposition获取文件名,这点跟服务器有关,需要灵活变通 if (filename == null || filename.length() < 1) { filename = absUrl.getFile(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (conn != null) { conn.disconnect(); conn = null; } } return filename; }
相关文章推荐
- Android 获取下载文件的真实名字
- 读懂Android (1):使用Android内部的DownloadProvider下载文件,并获取cache权限
- Android根据文件路径获取图片的名字
- Android HttpURLConnection 获取下载文件大小
- 获取flash里的真实url地址,将swf文件下载保存下来
- Android 打开文件管理器 获取文件的真实路径
- Java/Android 获取网络重定向文件的真实URL的示例代码
- Android之获取指定目录下的所有特殊文件名字
- android:根据下载文件的url获取文件名
- Android 获取下载链接文件大小
- 使用Android内部的DownloadProvider下载文件,并获取cache权限
- android 网络下载获取文件大小
- jasperReport如何获取jasper表格中title中的名字作为下载文件的名字
- android imageView 获取指定名字的图片、从MyEclipse服务器下载图片
- Android下载文件,如何获取实际的文件名
- Android OkHttp3(完美封装)Get异步获取数据、Post异步获取数据、Form表单提交、文件下载
- Java/Android 获取网络重定向文件的真实URL
- Android连接服务器,从服务器获取数据,以及从服务器下载文件(单,多线程)
- Android里根据下载文件的url获取文件名
- 使用Android内部的DownloadProvider下载文件,并获取cache权限 .