场景:需要读取指定文件的内容,此文件是手动存储到手机内置存储卡中的,且手机上不存在SD卡。

对于android通过activity提供的openFileOutput和openFileInput可以直接操作内置存储卡,但是保存到路径是用户看不到的:

创建的文件保存在/data/data/<package name>/files目录。

Environment.getExternalStorageDirectory()
这个方法是:当只有内置存储空间的时候,只能获取到内置存储空间的路径。
当内置存储空间和sd卡同时存在时候,只能获取Sd卡的路径,所以可以采用此方法进行。

public static String readURLConfig(){
String url = "#"; //默认的URL
try{
filePath = Environment.getExternalStorageDirectory().toString()+"/wd/config.txt";
}finally{
if(existsFile(filePath)){
try {
url = readFile(filePath);
} catch (IOException e) {
//
}
}
}
return url;
}
/*
* 判断文件是否存在
*/
public static boolean existsFile(String filePath){
File file = new File(filePath);
if(file.exists()){
return true;
}
return false;
} /*
* 读取文件
*/
public static String readFile(String filePath) throws IOException{
InputStream is = new FileInputStream(filePath);
int len = is.available();
byte []buffer = new byte[len];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while((is.read(buffer)) != -1){
baos.write(buffer);
}
byte []data = baos.toByteArray();
baos.close();
is.close();
return new String(data).trim();
}

Android 操作手机内置存储卡中的文件的更多相关文章

  1. 动态加载sd卡或者手机内置存储卡的so库

    package com.wsc.utils; import android.content.Context; import com.wsc.common.Entrance; import com.ws ...

  2. 手机QQ内置网页,微信内置网页中进行分享到QQ和微信的操作

    微信内的网页分享: API内容详见微信开发文档  https://mp.weixin.qq.com/wiki 这里需要注意的是:调用微信API的时候修改的是微信内网页右上角三个点那里打开后,选择分享之 ...

  3. android开发关于和使用本机内存、内置存储卡和外置存储卡 (转)

    转自:http://www.2cto.com/kf/201304/204729.html 关于android存储器简介:                  android开发常常需要涉及数据缓存,这就 ...

  4. 在Eclipse+ADT中开发Android系统的内置应用

    转自:  http://www.iteye.com/topic/1050439 在Eclipse+ADT中开发Android系统的内置应用 Android系统内置有:Browser(浏览器).Mms( ...

  5. 微信内置浏览器中,点击下拉框出现页面乱跳转现象(iphone)

    微信内置浏览器中,点击下拉框出现页面乱跳转现象(iphone) 前言: 这是小菜博客的第三篇文章.一直认为自己可以表达的东西太过简单,难以上台面,总是吝啬地不肯写.就算是写,也不知道从何开始.在同事的 ...

  6. Day07 数据类型(列表,元组,字典,集合)常用操作和内置方法

    数据类型 列表list: 用途:记录多个值(同种属性) 定义方式:[]用逗号分隔开多个任意类型的值 list()造出来的是列表,参数是可迭代对像,也就是可以使用for循环的对像 传入字典,出来的列表元 ...

  7. SSE 系列内置函数中的 shuffle 函数

    SSE 系列内置函数中的 shuffle 函数 邮箱: quarrying@qq.com 博客: http://www.cnblogs.com/quarryman/ 发布时间: 2017年04月18日 ...

  8. 转:jsp内置对象中page与pageContext与el内置对象pageScope与pageContext区别

    原文地址:jsp内置对象中page与pageContext与el内置对象pageScope与pageContext区别 首先说明一下jsp9大内置对象 (1)HttpSession类的session对 ...

  9. 微信内置浏览器中的cookie很诡异呀

    微信内置浏览器中的cookie很诡异呀 这是设置和删除COOKIE的代码 function set_cookie($var ,$value = '' ,$expire = 0){ $path = '/ ...

随机推荐

  1. documentElement vs body区别

    documentElement.scrollTop------>0因为,他包含head, body body.scrollTop------------------>才是正确的 scrol ...

  2. 抗忙,,建个MAVEN的私服仓库-NEXUS

    公司最近需求越来越上轨道,MAVEN的私服仓库-NEXUS构架起来哟.. 参考文档URL: http://www.linuxidc.com/Linux/2011-07/39578p3.htm http ...

  3. Codeforces 335B Palindrome

    http://codeforces.com/contest/335/problem/B 题意:  给定一个长度不超过5*10^4的只包含小写字母的字符串,要求你求它的回文子序列,如果存在长度为100的 ...

  4. CCI_chapter 2 Linked Lists

    2.1  Write code to remove duplicates from an unsorted linked list /* Link list node */ struct node { ...

  5. Delphi - GetUserNameEx(学一下导出Windows API,以及Array Char充当缓冲区的用法,下标必须从零开始)

    (* * Author : http://www.michael-puff.de * Date : 2006-03-29 * License : PUBLIC DOMAIN *) function G ...

  6. MySQL所有函数及操作符

    参考:Function and Operator Reference Name Description ABS() Return the absolute value ACOS() Return th ...

  7. PHP常用魔术方法(__call魔术方法:)

    魔术方法  __call <?php //文件名:index.php define('a',__DIR__); include '/IMooc/Loader.php'; spl_autoload ...

  8. 使用gfortran将数据写成Grads格式的代码示例

    使用gfortran将数据写成Grads格式的代码示例: !-----'Fortran4Grads.f90' program Fortran4Grads implicit none integer,p ...

  9. [ES6] ITERATORS

    Iterables return an iterator object. This object knows how to access items from a collection 1 at a ...

  10. 使用代码自定义UIView注意一二三

    文/CoderAO(简书作者)原文链接:http://www.jianshu.com/p/68b383b129f9著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 当一撮样式一样的视图在 ...