Android 本地路径
来源:互联网 发布:java页面导出excel 编辑:程序博客网 时间:2024/06/05 14:33
sd卡:Environment.getExternalStorageDirectory().getPath()/自己的文件目录
app安装的目录:this.getFilesDir() + File.separator + "文件夹名/" + fileName
: /data/data/包名/files/自己的文件夹名/文件名
手机内存的地址:"/storage/emulated/0/downloadimages/" + fileName
下载图片直接写入本地或者获取到bitmap:
private void getImage(String path) {URL url;InputStream in = null;FileOutputStream fileOutputStream = null;String fileName = getFileName(path);File parentFile = new File(getParentFilePath());if (!parentFile.exists()) {parentFile.mkdirs();}File file = new File(parentFile, fileName);try {url = new URL(path);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setConnectTimeout(5 * 1000);conn.setRequestMethod("GET");if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {in = conn.getInputStream();// bitmap = BitmapFactory.decodeStream(in);fileOutputStream = new FileOutputStream(file);byte buffer[] = new byte[1024 * 4];int temp = 0;while ((temp = in.read(buffer)) != -1) {fileOutputStream.write(buffer, 0, temp);}}} catch (MalformedURLException e) {e.printStackTrace();} catch (ProtocolException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (in != null) {try {in.close();} catch (IOException e) {e.printStackTrace();}}if (fileOutputStream != null) {try {fileOutputStream.close();} catch (IOException e) {e.printStackTrace();}}}}
保存图片到本地的一种方法:
public void saveImage(Bitmap bitmap, String fileName) {File parentFile = new File(getParentFilePath());if (!parentFile.exists()) {parentFile.mkdirs();}File file = new File(parentFile, fileName);FileOutputStream fileOutputStream = null;try {fileOutputStream = new FileOutputStream(file);bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);} catch (Exception e) {e.printStackTrace();} finally {try {if (fileOutputStream != null) {fileOutputStream.close();}} catch (IOException e) {e.printStackTrace();}}}
0 0
- Android 本地路径
- Android中的本地存储路径
- android 获取本地图片路径
- android获取本地视频路径
- android SharedPreferences类存储路径、本地数据库路径
- Android中读取asset路径下本地json文件
- android选择本地相册图片路径的问题的解决
- Android 获取本地存储路径的各种方法详解
- Android 截图 代码 截屏 保存图片到本地 根据本地图片路径 显示图片
- vsts本地配置路径
- java获取本地路径
- MySql数据文件本地路径
- Xcode - 修改本地路径
- gradle本地安装路径
- 本地host文件路径
- c# 获取本地路径
- nginx本地路径映射
- android 网络图片路径解析和本地图片路径解析的方法 ,base64加密报文解析成bitmap【代码示例】
- CNN五大经典模型:Lenet,Alexnet,Googlenet,VGG,DRL
- 2017年大数据可视化的3个趋势,有企业已经提前布局
- TCP丢包
- 程序员升级为需求分析员的过程,过了第一关后面就是光明大道
- LR-代理使用
- Android 本地路径
- 用OpenSystemArchitect进行数据库建模-简明教程
- sqoop
- F Decimal integer conversion
- iOS collectionView相册滑动
- 文章标题
- 欢迎使用CSDN-markdown编辑器
- Codeforces-2C Commentator problem(随机算法)
- 云之讯调短信接口