Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4040490
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:45:34+00:00 2026-05-20T12:45:34+00:00

This code URL listofFiles = this.getClass().getResource(someDir); File f = new File(listofFiles.toString()); File[] files =

  • 0

This code

URL listofFiles = this.getClass().getResource("someDir");
File f = new File(listofFiles.toString());
File[] files = f.listFiles();

runs in a JUnit unit test in a Tomcat webserver environment.

The URL that’s returned is most definitely valid. I’ve gone into the Finder in OS X, performed a “Go to Directory,” pasted in the value of listofFiles and seen all my files in the directory.

Why is listFiles() returning null?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:45:35+00:00Added an answer on May 20, 2026 at 12:45 pm

    According to the Javadoc for File.listFiles():

    Returns:
    An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.

    The fact that you are getting a null return value indicates that the path you are passing into the File constructor does not point to a directory.

    I suspect that passing the result of URL.toString() to the File constructor is building a path that is not what you think it is. Instead, try something like

    File f = new File(listofFiles.toURI());
    

    In addition, you might want to log the value of f.getAbsolutePath() to make sure that the path being read is the same as what you expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: if (System.IO.File.Exists(htmlLocation)) { vEarthBrowser.ObjectForScripting = this; vEarthBrowser.Url = new
I have this code: var url = textBox1.Text; WebClient wc = new WebClient(); var
This code doesn't work: URL url = new URL( xmlPath ); InputSource input =
I'm using this code, to make a request to a given URL: private static
Is there an easy way to modify this code so that the target URL
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I found the following code to create a tinyurl.com url: http://tinyurl.com/api-create.php?url=http://myurl.com This will automatically
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new
When I run this code url = ('http://maps.google.com/maps/nav?'+ 'q=from%3A'+from_address+ '+to%3A'+to_address+ '&output=json&oe=utf8&key='+api_key) request = urllib2.Request(url)
Okay, so I've been trying to load a BufferedImage using this code: URL url

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.