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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:54:56+00:00 2026-06-03T22:54:56+00:00

I like to keep my application data and and code in different Source Packages

  • 0

I like to keep my application data and and code in different Source Packages in NB (don’t mistake with java packages).

So I did this time. Unfortunately it can’t get files via File object from one package to another. Here’s my package structure

Source Packages
    |-[J]basicstuff
    |-[J]net.abc.utils
  assets
    |-[F]Images
    |-[F]Layouts

Legend:

  • No indication – source packages added in NB’s project properties
  • [J] Standard java package
  • [F] – folder for data made with file manager

The thing is, I have my custom layout loader as I use my own GUI system. Layouts are JSON text files placed in assets/Layouts. Unfortunately my layoutmanager (which is another class in net.abc.utils) can’t load them. Whatever I do, I can’t load those.

I’ve tried

File layout = new File("assets/Layouts/layout.txt");

then

File layout = new File("../../../assets/Layouts/layout.txt");

Then I remembered it is four directories above, including src dir.

File layout = new File("../../../../assets/Layouts/layout.txt");

But it didn’t work either.

Even tried

File layout = new File("../../../../Layouts/layout.txt");

and

File layout = new File("../../../Layouts/layout.txt");

But those of course also didn’t work. Can you help me?

  • 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-06-03T22:54:57+00:00Added an answer on June 3, 2026 at 10:54 pm

    Dependent on the environment in which your application is (Standalone, ApplicationServer), you will need to use the appropriate ClassLoader.

    Try something like this:

    private static InputStream getResourceAsStream(String resource) throws FileNotFoundException {
        String stripped = resource.startsWith("/") ? resource.substring(1) : resource;
        InputStream stream = null;
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            stream = classLoader.getResourceAsStream(stripped);
        }
        if (stream == null) {
            stream = MyClass.class.getResourceAsStream(resource);
        }
        if (stream == null) {
            stream = MyClass.class.getClassLoader().getResourceAsStream(stripped);
        }
        if (stream == null) {
            throw new FileNotFoundException("Resource not found: " + resource);
        }
        return stream;
    }
    

    For use:

    MyClass.getResourceAsStream("Layouts/layout.txt");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to keep my components/assemblies clearly separated from a source code point of
Background - For a winforms 3.5 c# application, I would like to keep the
I'm playing with bencoding and I would like to keep bencoded strings as Java
I have an ETL application which extracts data from a source database (for which
I would like to keep model binding when doing ajax calls from my view.
I'd like to keep my database clean of stale almost-accounts, and I was thinking
I'd like to keep some information on the client which element was clicked and
I'd like to keep my concrete classes separate from my views. Without using strongly
I would like to keep an item selected, on a ListView, when the user
I have a small JSF app and would like to keep some state on

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.