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 641671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:05:18+00:00 2026-05-13T21:05:18+00:00

I am working on a small basic GUI program that gets the files from

  • 0

I am working on a small basic GUI program that gets the files from my resources and gets the names of the files and places them in a combo box. for example i just have a file inside the same package called images and trying to get the files names. the way I get the file is by using the getResoure() like so

java.net.URL url = FileDemo.class.getResource("images");

but when I try to get the files inside the directory

  File urlfile = new File(url.toString());

  String[] files = urlfile.list();

the first line will convert the url to string and create a file object but when I try to get the list of files inside the directory it returns a null to the array of strings.

I broke down the code and used the debugger in netbeans found out, when it did the SecurityManager check it wouldn’t pass.

My question is are the files inside the project protected or there is no way to access them using the list() and listFiles() or am i doing something wrong? Also I ran the same script on my schools computer which they have windows 7 the code above worked. But when i ran it on my mac and even 2 win xp machines it just didn’t work? why is that ?

I hope this makes sense i am just stuck here still a new to java

Thanks in Advance.

  • 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-13T21:05:19+00:00Added an answer on May 13, 2026 at 9:05 pm

    The class to getResource(String) is returning a URL to images but there’s no guarantee that this is a file URL (beginning “file:”). If your class is embedded within a jar file this certainly won’t be the case, hence why it fails in some situations and not others.

    If your intention here is to actually make a portion of a file system visible to the user then I’d recommend avoiding getResource altogether, which is typically more useful when your application wishes to locate and load resources such as icons or config files.

    Instead, you could use JFileChooser, which is a rich Swing component for navigating the file system and selecting files.

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

Sidebar

Ask A Question

Stats

  • Questions 315k
  • Answers 315k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Apache Chainsaw V2 can load regular text log files, allowing… May 13, 2026 at 11:17 pm
  • Editorial Team
    Editorial Team added an answer If you've already got it as a byte array, then… May 13, 2026 at 11:17 pm
  • Editorial Team
    Editorial Team added an answer I have done this with a Virtual Machine before. I… May 13, 2026 at 11:17 pm

Related Questions

I am working on a small text editor project and want to add basic
The environment of my application: web-based, Spring MVC+Security, Hibernate, MySQL(InnoDB) I am working on
I'm currently working on a small iPhone game, and am porting the 3d engine
First shot at throwing a question on these boards so hopefully I can get
I am writing a website in my spare time for an educational facility and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.