我有一个"对象"由一个UUID和三个字符串组成的类
然后我有三个文件夹路径,其中两个包含图像和最后一个视频。
所有"所属的文件"除了扩展名(.jpg
,.mp4
)
我如何最好地对这些文件夹进行排序并为每个值收集匹配的文件名+路径,以便我可以创建带有这些值的符号实例,然后将该实例放在ArrayList<Signs>
中?
此刻我有点迷失了:)
public class Signs {
UUID id;
String name;
String videoURL;
String imageURL;
String illustrativeURL;
public Signs(String name,String videoURL,String imageURL,String illustrativeURL){
this.id = UUID.randomUUID();
this.name = name;
this.videoURL = videoURL;
this.imageURL = imageURL;
this.illustrativeURL = illustrativeURL;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVideoURL() {
return videoURL;
}
public void setVideoURL(String videoURL) {
this.videoURL = videoURL;
}
public String getBitmapURL() {
return imageURL;
}
public void setBitmapURL(String bitmapURL) {
this.imageURL = bitmapURL;
}
public UUID getId() {
return id;
}
}
这是我在班级中使用的方法,根据每个文件夹的设置路径查看文件夹。
public ArrayList<Signs> getArrayOfSignsFromFolder(String imagePath,String videoPath,String illustrativePath){
ArrayList<Signs> arrayOfSignItems = new ArrayList<Signs>();
Signs sign;
File imagedirectory = new File(imagePath);
File videodirectory = new File(videoPath);
File illustrativedirectory = new File(illustrativePath);
File[] imageListing = imagedirectory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if(name.toLowerCase().endsWith(".jpg")){
return name.toLowerCase().endsWith(".jpg");
}
else{
return false;
}
}});
File[] videoListing = videodirectory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if(name.toLowerCase().endsWith(".mp4")){
return name.toLowerCase().endsWith(".mp4");
}
else{
return false;
}
}});
File[] illustrativeListing = illustrativedirectory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if(name.toLowerCase().endsWith(".jpg")){
return name.toLowerCase().endsWith(".jpg");
}
else{
return false;
}
}});
for (int i = 0; i < imageListing.length; i++){
}
if(imageListing != null)
{
// hmmmm......... Any suggestions how to handle this?
}
else{
return null;
}
return arrayOfSignItems;
}