一:固定图片大小:

(1)新建如下文件(2)设置view 宽和高 android:layout_wdith="@dimen/xxx" android:layout_height="@dimen/xxx"

        
  1. 1.固定图片大小
  2. Android:layout_width=”@dimen/~~”
  3. <?xmlversion="1.0"encoding="utf-8"?>
  4. <resources>
  5. <dimenname="list_talk_item_image_width">163dp</dimen>
  6. <dimenname="list_talk_item_image_height">116dp</dimen>
  7. </resources>

二:1.(1) 判断SD卡是否插入

Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

 (2)获得sd卡根目录

File skRoot = Environment.getExternalStorageDirectory();

(3) 获得私有根目录

 File fileRoot = Context.getFilesDir()+"\";

(4) 确定或获得文件夹和文件路径

  String path = File.getPath();//相对

  String path = File.getAbsoultePath();//绝对

(5) 获得文件或文件夹的父目录

 String parentPath = File.getParent()

(6) 获得文件或文件夹的名称:

  String Name = File.getName();

(7) 建立文件或文件夹

  File.createNewFile();//建立文件

(8) 判断是文件或文件夹

 File.isDirectory()

(9) 列出文件夹下的所有文件和文件夹名

File[] files = File.listFiles();

(10) 修改文件夹和文件名

File.renameTo(dest);

(11) 删除文件夹或文件

File.delete();

(12) 文件读写模式

  Context.MODE_PRIVATE:新内容覆盖原内容

   Context.MODE_APPEND:新内容追加到原内容后

  Context.MODE_WORLD_READABLE:允许其他应用程序读取

  Context.MODE_WORLD_WRITEABLE:允许其他应用程序写入,会覆盖原数据。

  /*** 保存文件

  * @param fileName

  * @param fileContent

  * @throws Exception*/

  public void save(String fileName, String fileContent) throws Exception {

  // Activity的父类的父类就是contextcontext与其他框架中的context相同为我们以供了一些核心操作工具。

  FileOutputStream fileOutputStream = this.context.openFileOutput(

  fileName, Context.MODE_PRIVATE);

  fileOutputStream.write(fileContent.getBytes());

 }

 /** 读取文件

  * @param fileName

  * @return

  * @throws Exception

*/

  public String read(String fileName) throws Exception {

  FileInputStream fileInputStream = this.context.openFileInput(fileName);

  ByteArrayOutputStream byteArray = new ByteArrayOutputStream();

  byte[] buffer = new byte[1024];

  int len = 0;

  while ((len = fileInputStream.read(buffer)) > 0) {

  byteArray.write(buffer, 0, len);

  };

  return byteArray.toString();

  }

  }

更多相关文章

  1. Android中TextView中内容不换行的解决方法
  2. android读写文件
  3. Android内核的根文件系统
  4. android获取文件目录
  5. Android代码实现APK文件的安装与卸载

随机推荐

  1. Android获取本机Mac地址及IP地址方法
  2. RHEL5 CENTOS5上编译Android内核的步骤
  3. 关于android在Service中弹出Dialog对话框
  4. Professional Android(安卓)2 Developmen
  5. Android(安卓)Bundle类
  6. Android获取apk的版本及包名等信息
  7. Android(安卓)升级问题
  8. android有用网址
  9. Android之Google Map(一)
  10. Android(安卓)常用的权限