首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

读取手机本map片和文本文件(Lwuit版)

2012-11-04 
读取手机本地图片和文本文件(Lwuit版)读取手机存储文件的核心代码:package com.mopietekimport java.io.I

读取手机本地图片和文本文件(Lwuit版)
读取手机存储文件的核心代码:



package com.mopietek;import java.io.IOException;import java.util.Hashtable;import com.sun.lwuit.Image;public class IconHelper {//图标资源private Image imgFolder;private Image unknownImage;private Image textImage;//Audioprivate Image audioImage;//Pictureprivate Image picImage;private Image jpgImage;//Videoprivate Image sgpImage;private Image aviImage;private Image wmvImage;private Image mpgImage;//Webprivate Image zipImage;private Image htmlImage;private Image xmlImage;//Sourceprivate Image cImage;private Image cppImage;private Image headerImage;//图标管理容器private Hashtable iconTable;public IconHelper(){iconTable = new Hashtable();try{//载入图标资源imgFolder = Image.createImage("/filetype/folder.png");unknownImage = Image.createImage("/filetype/unknown.png");textImage = Image.createImage("/filetype/text.png");//AudioaudioImage = Image.createImage("/filetype/audio.png");//PicturepicImage = Image.createImage("/filetype/pic.png");jpgImage = Image.createImage("/filetype/jpg.png");//VideosgpImage = Image.createImage("/filetype/3gp.png");aviImage = Image.createImage("/filetype/avi.png");wmvImage = Image.createImage("/filetype/wmv.png");mpgImage = Image.createImage("/filetype/mpg.png");//WebzipImage = Image.createImage("/filetype/zip.png");htmlImage = Image.createImage("/filetype/html.png");xmlImage = Image.createImage("/filetype/xml.png");//SourcecImage = Image.createImage("/filetype/c.png");cppImage = Image.createImage("/filetype/cpp.png");headerImage = Image.createImage("/filetype/header.png");}catch(IOException e){//图标资源imgFolder = null;               unknownImage = null;               textImage = null;               //Audio               audioImage = null;               //Picture               picImage = null;               jpgImage = null;               //Video               sgpImage = null;               aviImage = null;               wmvImage = null;               mpgImage = null;               //Web               zipImage = null;               htmlImage = null;               xmlImage = null;               //Source               cImage = null;               cppImage = null;               headerImage = null;               e.printStackTrace();  }initTable();}private void initTable() {       //Key为扩展名(不包括'.'符号),值为content typeiconTable.put("/", imgFolder);iconTable.put("", unknownImage);iconTable.put("txt", textImage);//SourceiconTable.put("c", cImage);iconTable.put("cpp", cppImage);iconTable.put("h", headerImage);//WebiconTable.put("html", htmlImage);iconTable.put("htm", htmlImage);iconTable.put("xml", xmlImage);iconTable.put("zip", zipImage);iconTable.put("jar", zipImage);//audioiconTable.put("mp3", audioImage);iconTable.put("wma", audioImage);iconTable.put("mid", audioImage);iconTable.put("wav", audioImage);//PictureiconTable.put("gif", picImage);iconTable.put("png", picImage);iconTable.put("jpg", jpgImage);iconTable.put("jepg", jpgImage);//VideoiconTable.put("3gp", sgpImage);iconTable.put("avi", aviImage);iconTable.put("wmv", wmvImage);iconTable.put("mpeg", mpgImage);iconTable.put("mpg", mpgImage);iconTable.put("mp4", mpgImage);}    //按照扩展名(不包括'.'符号) 获取文件的图标对象public Image getIconByExt(final String extension) {Image temp = (Image) iconTable.get(extension);//是否为空,则使用默认图标替代return ((temp == null) ? unknownImage : temp);}}


程序代码所使用到的图片可在附件中下载,在真机上测试程序,可能部分手机不支持jpg和gif格式的图片,程序可能会报IOException。

热点排行