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

JSR75学习札记

2012-08-25 
JSR75学习笔记/* 目录文件列表 */public Vector list(String path) {try {FileConnection fc (FileConne

JSR75学习笔记

/* 目录文件列表 */public Vector list(String path) {try {FileConnection fc = (FileConnection) (Connector.open(path));if (fc.exists()) {Vector listVec = new Vector(0, 1);Enumeration en = fc.list();while (en.hasMoreElements()) {listVec.addElement((String) (en.nextElement()));}return listVec;} elsereturn null;} catch (Exception e) {System.out.println("listErr:" + e.toString());return null;}}

/* 保存文件 */public void saveFile(String path, byte[] fileData) {try {FileConnection fc = (FileConnection) (Connector.open(path));fc.create();fc.setWritable(true);OutputStream os = fc.openOutputStream();os.write(fileData);os.close();} catch (Exception e) {System.out.println("saveFileErr:" + e.toString());}}

/* 删除文件 */public void deleteFile(String path) {try {FileConnection fc = (FileConnection) (Connector.open(path));if (fc.exists())fc.delete();} catch (Exception e) {System.out.println("deleteFileErr:" + e.toString());}}

/* 读取文件 */public byte[] readFile(String path) {try {FileConnection fc = (FileConnection) (Connector.open(path));if (fc.exists()) {InputStream is = fc.openInputStream();byte[] temp = new byte[is.available()];is.read(temp);is.close();return temp;} elsereturn null;} catch (Exception e) {System.out.println("readFileErr:" + path + e.toString());return null;}}

?

此方法也不用多解释了。

以上是关于文件操作的最基本的一些功能,也是第一期的学习笔记研究到的内容,更多的内容,过几天继续研究继续写吧,呵呵。

原文转自J2ME开发网----作者:刀剑啸

热点排行