菜鸟学习之路
public class Test {
public static List findFiles(String baseDirName,String targetFileName){
List fileList=new ArrayList();
File baseDir=new File(baseDirName);
if(!baseDir.exists()||!baseDir.isDirectory()){
System.out.println("文件查找失败");
return fileList;
}
String tempName=null;
Queue queue=new LinkedList<File>();
queue.add(baseDir);
System.out.println(baseDir.getAbsolutePath());//这里这里
File tempFile=null;
while(!queue.isEmpty()){
tempFile=(File)queue.poll();
if(tempFile.exists()&&tempFile.isDirectory()){
File[] files=tempFile.listFiles();
for(int i=0;i<files.length;i++){
if(files[i].isDirectory())
queue.add(files[i]);
else {
tempName=files[i].getName();
if(Test.wildcardMatch(targetFileName,tempName)){
fileList.add(files[i].getAbsoluteFile());
}
}
}
}
}
return fileList;
}
private static boolean wildcardMatch(String pattern,String str){
int patternLength=pattern.length();
int strLength=str.length();
int strIndex=0;
char ch;
for(int patternIndex=0;patternIndex<patternLength;patternIndex++){
ch=pattern.charAt(patternIndex);
if(ch=='*'){
while(strIndex<strLength){
if(wildcardMatch(pattern.substring(patternIndex+1),str.substring(strIndex)))
return true;
strIndex++;
}
}else if (ch=='?'){
strIndex++;
if (strIndex>strLength)
return false;
}else {
if(strIndex>=strLength||ch!=str.charAt(strIndex))
return false;
strIndex++;
}
}
return (strIndex==strLength);
}
public static void main(String[] args){
List resultList=Test.findFiles("E:","*.txt");
for(int i=0;i<resultList.size();i++)
System.out.println(resultList.get(i));
}
}
以上代码是照着原书打的
为何不能搜索磁盘目录(“E:” 会定位到当前包路径,搜索却是正常的 ),一定要输入磁盘下的子目录才行(”E:\Java“ 一切正常)
如果是别的盘(“D:” 就会输出 “D:\” 为何会有 "\" 啊啊啊啊,然后抛出异常),别的盘下的子目录也一切正常。
public static List findFiles(String baseDirName,String targetFileName){
List fileList=new ArrayList();
File baseDir=new File(baseDirName);
if(!baseDir.exists()||!baseDir.isDirectory()){
System.out.println("文件查找失败");
return fileList;
}
String tempName=null;
Queue queue=new LinkedList<File>();
queue.add(baseDir);
System.out.println(baseDir.getAbsolutePath());//这里这里
File tempFile=null;
while(!queue.isEmpty()){
tempFile=(File)queue.poll();
if(tempFile.exists()&&tempFile.isDirectory()){
File[] files=tempFile.listFiles();
for(int i=0;i<files.length;i++){
if(files[i].isDirectory())
queue.add(files[i]);
else {
tempName=files[i].getName();
if(Test.wildcardMatch(targetFileName,tempName)){
fileList.add(files[i].getAbsoluteFile());
}
}
}
}
}
return fileList;
}
private static boolean wildcardMatch(String pattern,String str){
int patternLength=pattern.length();
int strLength=str.length();
int strIndex=0;
char ch;
for(int patternIndex=0;patternIndex<patternLength;patternIndex++){
ch=pattern.charAt(patternIndex);
if(ch=='*'){
while(strIndex<strLength){
if(wildcardMatch(pattern.substring(patternIndex+1),str.substring(strIndex)))
return true;
strIndex++;
}
}else if (ch=='?'){
strIndex++;
if (strIndex>strLength)
return false;
}else {
if(strIndex>=strLength||ch!=str.charAt(strIndex))
return false;
strIndex++;
}
}
return (strIndex==strLength);
}
public static void main(String[] args){
List resultList=Test.findFiles("E:","*.txt");
for(int i=0;i<resultList.size();i++)
System.out.println(resultList.get(i));
}
}
以上代码是照着原书打的
为何不能搜索磁盘目录(“E:” 会定位到当前包路径,搜索却是正常的 ),一定要输入磁盘下的子目录才行(”E:\Java“ 一切正常)
如果是别的盘(“D:” 就会输出 “D:\” 为何会有 "\" 啊啊啊啊,然后抛出异常),别的盘下的子目录也一切正常。
...全文
相关推荐
菜鸟EclipseRCP学习之路
NULL 博文链接:https://gongqi.iteye.com/blog/819868
菜鸟学习单片机如何下手?
单片机的学习者有初入职场的菜鸟工程师,有渴求知识的在校大学生,也有迫于项目需求的电子工程师。迫于项目需求转换开发平台的电子工程师往往具备其他类型单片机的使用经验,学习新类型的单片机并不会有太大的障碍,但是菜鸟工程师和在校大学生就是真正的“初学者”。初学者在开始学习单片机的时候都有一个相同的问题那就是“怎么才能尽快地学会使用单片机?” 菜鸟工程师由于身边有“老兵”的指导,加之有目的明确的工程项目的驱动,在单片机学习上并不会走太多的弯路。在校大学生在学习之初,首先要面对的就是“迷茫”,空有一腔热情,却不知如何下手。 在学习单片机之初应当有一些基础知识准备。单片机是电子技术发展到一定程度
vivado时序菜鸟学习
转载,用作共同学习,vivado时序分析,菜鸟工程师入门级别可进入。
w3school和菜鸟教程学习手册.zip
全部的编程方面的手册整合到一起,全部方面的都包含
菜鸟黑客技术入门学习方法
总结了一下我个人的一些学习方法与心得希望能给刚入门的朋友一些参考,使其少走弯路。如果您是一只老鸟,觉得这个教程对您毫无帮助,那么请您跳过此教程,毕竟不是所有人都像您一样掌握了良好的学习方法,那些迷惑中的菜鸟,正需要这样一个教程!


非技术区
