SDCard File Util : SDCard « Hardware « Android






SDCard File Util

  

//package edu.dhbw.andobjviewer.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.lang.reflect.Field;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class SDCardFileUtil extends BaseFileUtil {  



  /* (non-Javadoc)
   * @see edu.dhbw.andobjviewer.util.FileUtilInterface#getReaderFromName(java.lang.String)
   */
  public BufferedReader getReaderFromName(String name) {
    if (baseFolder != null) {
      try {
        return new BufferedReader(new FileReader(new File(baseFolder, name)));
      } catch (FileNotFoundException e) {
        return null;
      }
    } else {
      try {
        return new BufferedReader(new FileReader(new File(name)));
      } catch (FileNotFoundException e) {
        return null;
      }
    }
  }
  
  /* (non-Javadoc)
   * @see edu.dhbw.andobjviewer.util.FileUtilInterface#getBitmapFromName(java.lang.String)
   */
  public Bitmap getBitmapFromName(String name) {
    if (baseFolder != null) {
      String path = new File(baseFolder,name).getAbsolutePath();
      return BitmapFactory.decodeFile(path);
    } else {
      return BitmapFactory.decodeFile(name);
    }
  }
}
abstract class BaseFileUtil {
  
  protected String baseFolder = null;

  /* (non-Javadoc)
   * @see edu.dhbw.andobjviewer.util.FileUtilInterface#getBaseFolder()
   */
  public String getBaseFolder() {
    return baseFolder;
  }

  /* (non-Javadoc)
   * @see edu.dhbw.andobjviewer.util.FileUtilInterface#setBaseFolder(java.io.File)
   */
  public void setBaseFolder(String baseFolder) {
    this.baseFolder = baseFolder;
  }

  /**
   * get an reader through it's filename
   * @param name
   * @return may be null, in case of an exception 
   */
  public abstract BufferedReader getReaderFromName(String name);

  /**
   * get a bitmap object through an filename.
   * @param name
   * @return may be null, in case of an exception 
   */
  public abstract Bitmap getBitmapFromName(String name);

}

   
    
  








Related examples in the same category

1.Load image from mounted sdcard
2.Uri for sdcard
3.Get SDCard Megs Free
4.create File In SDCard
5.export the current database to the SDcard
6.get Sd card Path