我在学习android写入文件时遇到了这样一个问题,我想将一个已经存在于项目资源文件中的文件写入SD卡中,
Resources resources=getBaseContext().getResources();
is=resources.openRawResource(imageAdapter.imageIDs[index]);
其中imageAdapter.imageIDs[index]是资源文件的索引//取得资源文件的名称
String entryName=resources.getResourceEntryName(imageAdapter.imageIDs[index]);
但是不知道怎么样取得资源文件的后缀名,因为我想在这句代码中使用
File newFile=new File(root,"123.jpg");
我不想在代码中将文件名限制死,各位大虾帮帮忙,我弄了一个下午了还是没找到用什么方法来实现
Resources resources=getBaseContext().getResources();
is=resources.openRawResource(imageAdapter.imageIDs[index]);
其中imageAdapter.imageIDs[index]是资源文件的索引//取得资源文件的名称
String entryName=resources.getResourceEntryName(imageAdapter.imageIDs[index]);
但是不知道怎么样取得资源文件的后缀名,因为我想在这句代码中使用
File newFile=new File(root,"123.jpg");
我不想在代码中将文件名限制死,各位大虾帮帮忙,我弄了一个下午了还是没找到用什么方法来实现
class MusicFilter implements FilenameFilter
{
public boolean accept(File dir, String name)
{
//这里还可以设置其他格式的音乐文件
return (name.endsWith(".mp3"));
}
}
MimeType请参考http://en.wikipedia.org/wiki/MIME_type#List_of_common_media_types
上面少写了一个字:string.subString(string.lastIndexOf("."))
对于图片资源一样适用。