J2ME:JSR75包的使用和事列!
来源:互联网 发布:mac版本ai破解 编辑:程序博客网 时间:2024/05/16 17:05
一.获取指定路径的目录和文件列表
/*目录文件列表*/
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;
}
else
return null;
}
catch(Exception e)
{
System.out.println("listErr:"+e.toString());
return null;
}
}
方法里的path参数就是要查找的路径,比如file:///c:/pictures/,切记,如果是目录Path,那么后面的/一定不能省,否则会查找不到内容。这个方法返回的是一个包含了指定Path下的所有目录名和文件名的向量。
二.建立或者保存一个文件到指定路径
/*保存文件*/
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());
}
}
fileData是需要保存的文件内容,可以是声音,也可以是图像,或者文字之类
三.删除指定文件
/*删除文件*/
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;
}
else
return null;
}
catch(Exception e)
{
System.out.println("readFileErr:"+path+e.toString());
return null;
}
}
此方法也不用多解释了
- J2ME:JSR75包的使用和事列!
- [J2ME]文件操作-JSR75包使用总结
- J2ME文件操作——JSR75包
- J2ME文件系统的操作(JSR75)
- j2me中的文件操作包JSR75入门讲解
- J2ME JSR75 FileConnection行为研究
- JSR75和MOTO FileConnection的真机表现
- 新手使用MyEclipse开发J2me对res包的理解
- J2ME中MMAPI(JSR135)包的使用
- J2ME开发环境的安装和使用
- J2ME开发环境的安装和使用
- J2ME中List和Alert的使用
- JSR75在非签名MIDlet中的使用
- 查看手机的jsr75是否可用方法
- 熟练使用J2ME可选包MMAPI
- 熟练使用J2ME可选包MMAPI
- J2ME使用Kxml2包解析XML
- 熟练使用J2ME可选包MMAPI
- C# 调用 java webservice 的问题
- UpdateWindow
- 我对Log4J的一点初认识- -
- [观点]蒋劲松:敬畏自然才能真正大有作为
- NEC中国研究院 07暑期实习 面试+笔试题
- J2ME:JSR75包的使用和事列!
- 表单控件制作
- 拾惠
- 闲扯
- 使用 __declspec(dllexport) 从 DLL 导出
- HR - 关于人力资源
- 2007.7.1下午
- ScrollWindow
- Java学习的30个目标