如何遍历网络文件夹并取得文件名 我的目的是访问特定的文件夹,读取里面所有的图片文件名假定图片目录是 //image/ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*; public class Decode { static String is_jadpath; public static void main(String[] args) { try{ if (args.length>1) { is_jadpath=args[0]; File f=new File(args[1]); if (f.isDirectory()) { File newdic=new File(args[1]+"_src"); newdic.mkdir(); recursionFileList(newdic.getPath(),f); } else { Runtime r=Runtime.getRuntime(); String dimpath=args[1].substring(0,args[1].lastIndexOf('\\')); String cmd=is_jadpath+" -d "+dimpath+" -s java "+args[1]; r.exec(cmd); } } else { System.out.println("please input argument"); System.out.println("example d:\\jadhome\\jad c:\\yourdic\\yourclass.class"); } }catch(Exception e) {System.out.println("wrong:"+e);} } private static boolean recursionFileList(String dimparentpath,File f) throws Exception { boolean hasClassFile=false; File flist[]=f.listFiles(); for(int i=0;i<flist.length;i++) { if (flist[i].isDirectory()) { String srcpath=flist[i].getPath(); String dimpath=dimparentpath+srcpath.substring(srcpath.lastIndexOf('\\')); File newdic=new File(dimpath); newdic.mkdir(); if (!recursionFileList(dimpath,flist[i])) newdic.delete(); else { Runtime r=Runtime.getRuntime(); String cmd=is_jadpath+" -d "+dimpath+" -s java "+srcpath+"\\*.class"; r.exec(cmd); } } else if (flist[i].getPath().endsWith(".class")) { hasClassFile=true; Runtime r=Runtime.getRuntime(); String cmd=is_jadpath+" -d "+dimparentpath+" -s java "+flist[i].getPath(); r.exec(cmd); } } return hasClassFile; } } 上面是java遍历一个目录,并读出其中所有的文件名,楼主参考一下 利用ServletContext获得图片文件夹真实路径,参照楼上方法可读出文件名。 用FILE读一个目录下文件的集合 应该不是太难吧 不过如果你是通过客户端访问服务端并且想访问服务端的目录的集合那不太可能 除非服务端给你提供这个功能我这里有个JSP文件 是一般小公司用来管理服务器文件的东西(偶尔也会被黑客拿去用) 如果你想要的话留下邮箱 我发给你 我来推荐一个在线试听课程http://www.cdlanah.com/zxst/ 关于用户注销跳转页问题 谁给我解释一下!!! 求一个 Flex 中 读写操作用的包 求救stucts异常 jsp与sql server连接乱码问题!共同探讨,来者有分! 各位高手请帮帮忙 帮我把问题解决了 好吗?拜托各位 如果在网页上实现树状的结构,大家有没有实例代码可以给小弟参考一下! 求救!!!如何在使一个javabean按页返回ResultSet??? 请教在JSP页面上个别字是乱码的问题 springboot使用Druid时报错 我想写一个servlet,贴出代码,请大家帮我看看,我是小菜鸟 急,
public class Decode
{
static String is_jadpath;
public static void main(String[] args)
{
try{
if (args.length>1)
{
is_jadpath=args[0];
File f=new File(args[1]);
if (f.isDirectory())
{
File newdic=new File(args[1]+"_src");
newdic.mkdir();
recursionFileList(newdic.getPath(),f);
}
else
{
Runtime r=Runtime.getRuntime();
String dimpath=args[1].substring(0,args[1].lastIndexOf('\\'));
String cmd=is_jadpath+" -d "+dimpath+" -s java "+args[1];
r.exec(cmd);
}
}
else
{
System.out.println("please input argument");
System.out.println("example d:\\jadhome\\jad c:\\yourdic\\yourclass.class");
}
}catch(Exception e)
{System.out.println("wrong:"+e);}
}
private static boolean recursionFileList(String dimparentpath,File f)
throws Exception
{
boolean hasClassFile=false;
File flist[]=f.listFiles();
for(int i=0;i<flist.length;i++)
{
if (flist[i].isDirectory())
{
String srcpath=flist[i].getPath();
String dimpath=dimparentpath+srcpath.substring(srcpath.lastIndexOf('\\'));
File newdic=new File(dimpath);
newdic.mkdir();
if (!recursionFileList(dimpath,flist[i]))
newdic.delete();
else
{
Runtime r=Runtime.getRuntime();
String cmd=is_jadpath+" -d "+dimpath+" -s java "+srcpath+"\\*.class";
r.exec(cmd);
}
}
else if (flist[i].getPath().endsWith(".class"))
{
hasClassFile=true;
Runtime r=Runtime.getRuntime();
String cmd=is_jadpath+" -d "+dimparentpath+" -s java "+flist[i].getPath();
r.exec(cmd);
}
}
return hasClassFile;
}
} 上面是java遍历一个目录,并读出其中所有的文件名,楼主参考一下