Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Iam working in a desktop application for windows version using java. In my application there is a requirement to search all .php

i use recursive methods;

and REGEX

my code :

import java.io.File;


public class Copier {
public static void find(String source,String rep)
{
    File src=new File(rep);
    if(src.exists() && src.isDirectory())
    {
        String[] tab=src.list();
        for(String s:tab)
        {
            File srcc=new File(rep+""+s);
            if(srcc.isFile())
            {  
                if(srcc.getName().matches(".*"+source+"$"))
                System.out.println(s);
            }

            else
                find(source,srcc.getAbsolutePath());
        }
    }
}

public static void main(String[] args)
{
    find(".php","C:");
}
}

But i have this exception :

Exception in thread "main" java.lang.NullPointerException
    at Copier.find(Copier.java:11)
    at Copier.find(Copier.java:21)
    at Copier.main(Copier.java:28)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
131 views
Welcome To Ask or Share your Answers For Others

1 Answer

src.list() returns null. It probably happens because you (current user) does not have access rights to the directory. I guess it is about C: (the root directory of disk C). This often happens especially on Windows 7.

First try to debug your code using directory where you have access rights. Then fix your code to care about nulls. Then try to run your program as an administrator.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...