解析图像目录
问题描述:
我与play framework工作,我有我的部署应用程序的问题上playapps.net,我还没有localy。 他在这里的我的代码:解析图像目录
public static void image(Long idCategorieProject, Long idImage)
{
CategorieProject categorieproject = CategorieProject.findById(idCategorieProject);
List<Categorie> categories = Categorie.all().fetch();
// SMALL IMAGES
List<String>smallImages = null;
try
{
File dirSmall = new File("public/images/projects/"+idCategorieProject+"/small/");
smallImages = new ArrayList();
File[] smallImageFiles = dirSmall.listFiles();
for (int i = 0; i < smallImageFiles.length; i++) {
smallImages.add(smallImageFiles[i].getName());
}
} catch (Exception e) {
System.out.println(e);
}
// FULL IMAGE
List<String>fullImages = null;
try
{
File dirSmall = new File("public/images/projects/"+idCategorieProject+"/full/");
fullImages = new ArrayList();
File[] fullImageFiles = dirSmall.listFiles();
for (int i = 0; i < fullImageFiles.length; i++) {
if (i == idImage)
fullImages.add(fullImageFiles[i].getName());
}
} catch (Exception e) {
System.out.println(e);
}
render(lang, categorieproject, categories, fullImages, smallImages);
}
Localy,我的图片数组不为空,我可以显示它们,但与部署的版本,它似乎阵列为空。有没有另一种解析图像目录的解决方案?
答
您使用相对路径为您的文件,这可能会导致该应用程序的执行,从依赖问题。
使用核心Play中可用的VirtualFile(play.vfs.VirtualFile)对象并使用fromRelativePath(String path)
方法,您会更安全。
欲了解更多信息,你可以看看这个帖子 - How to access a resource file using relative path in play framework project?,或简单地搜索VirtualFile [Playframework]
堆栈溢出。
答
如果你有当,而不是当它在本地运行的应用程序部署列出文件问题,那么也许这是一个权限问题。