怎样获取某个文件夹内所有图片的路径,并保存在一个数组里

怎样获取某个文件夹内所有图片的路径,并保存在一个数组里,第1张

给你段代码,path就是你说的某个文件夹
//遍历path,将所有可处理的文件放入数组
Vector<String> imagePathArray=new Vector<String>();
File dir = new File(path);
File file[] = dirlistFiles();
for (int i = 0; i < filelength; i++) {
if (file[i]isFile())
{
String icon=file[i]getAbsolutePath();
if (iconendsWith("png") || iconendsWith("PNG") ||//这里仅仅加入png和jpg文件格式,需要其他格式就在这里增加判断
iconendsWith("jpg") || iconendsWith("jpg"))
imagePathArrayadd(icon);
}
}

<div class="test">
    <img src="testjpg"/>
</div>$(function(){
  var url = $('test img')attr("src");
  alert(url);
});

jQuery的attr属性可以返回元素属性,如上代码所示

attr(name|preperties|key,value|fn)详解

参数

name :属性名称

properties:作为属性的"名/值对"对象

key,value:属性名称

fn:调用函数


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/10534877.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-09
下一篇 2023-05-09

发表评论

登录后才能评论

评论列表(0条)

保存