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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:19:24+00:00 2026-06-05T01:19:24+00:00

I am developing a graphical installer for our application. Since none of the available

  • 0

I am developing a graphical installer for our application. Since none of the available installer generators meet the requirements and constraints, I am building it from scratch.

The installer is supposed to run on several operating systems, and therefore the path handling needs to be OS-agnostic. I have written the following small utility for this purpose:

public class Path {
  private Path() {
  }

  public static String join(String... pathElements) {
    return ListEnhancer.wrap(Arrays.asList(pathElements)).
      mkString(File.separator);
  }

  public static String concatOsSpecific(String path, String element) {
    return path + File.separator + element;
  }

  public static String concatOsAgnostic(String path, String element) {
    return path + "/" + element;
  }

  public static String makeOsAgnostic(String path) {
    return path.replace(File.separator, "/");
  }

  public static String makeOsSpecific(String path) {
    return new File(path).getAbsolutePath();
  }

  public static String fileName(String path) {
    return new File(path).getName();
  }
}

Now my code is littered with Path.*Agnostic and Path.*Specific calls in many places. As is apparent, this is very error-prone and not transparent at all.

What approach should I take to make the path handling transparent and less error-prone? Do there exist any utilities/libraries that already address this problem? Any help would be greatly appreciated.

EDIT:

To exemplify what I mean, here is some code I wrote a while ago. (Offtopic: Forgive the long-ish method. The code is in initial stages, and will be undergoing some heavy refactoring soon.)

Some context: ApplicationContext is an object that stores the installation data. That includes several paths such as installationRootDirectory, installationDirectory etc. The defaults for these are specified when creating an installer, and hence are always stored in OS-agnostic formats.

@Override
protected void initializeComponents() {
  super.initializeComponents();
  choosePathLabel = new JLabel("Please select the installation path:");
  final ApplicationContext c = installer.getAppContext();
  pathTextField = new JTextField(
    Path.makeOsSpecific(c.getInstallationDirectory()));
  browseButton = new JButton("Browse", 
    new ImageIcon("resources/images/browse.png"));
  browseButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      JFileChooser fileChooser = new JFileChooser();
      fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      fileChooser.setAcceptAllFileFilterUsed(false);
      int choice = fileChooser.showOpenDialog(installer);
      String selectedInstallationRootDir = fileChooser.getSelectedFile().
        getPath();
      if (choice == JFileChooser.APPROVE_OPTION) {
        c.setInstallationRootDirectory(
          Path.makeOsAgnostic(selectedInstallationRootDir));
        pathTextField.setText(Path.makeOsSpecific(c.getInstallationDirectory()));
      }
    }
  });
}
  • 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-05T01:19:26+00:00Added an answer on June 5, 2026 at 1:19 am

    Or you could introduce 2 new classes:

    class OsSpecificPath implements FilePathInterface
    {
          String path;
    
          OsAgnosticPath toAgnosticPath();
    
          OsSpecificPath concat( OsSpecificPath otherPath );
    
          // from IFilePath
          getFile();
    
         ... etc
    }
    

    and

    class OsAgnosticPath implements FilePathInterface
    {
          String path;
    
          OsSpecificPath toOsSpecificPath();
    
          OsAgnosticPath concat( OsAgnosticPath otherPath );
    
          // from IFilePath
          getFile();
    
         ... etc
    }
    

    each wrap a path however they need to.

    each method could then have methods to convert to the other type of path, but instead of a “stringly-typed” solution where everything is a string and can be misused, you’d have 2 strongly typed classes that can’t be incorrectly passed around.

    Anything that doesn’t care about the type of path would use FilePathInterface, anything that needs to operate on specific kinds of paths would use those types specificly. FilePathInterface could hypothetically have both toAgnosticPath and toOsSpecificPath in the interface if really necessary…

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

Sidebar

Related Questions

I am currently developing a query builder application, basically, a simple graphical interface that
i dont how to solve this problem. I am developing a graphical editor, where
I'm developing a graphics-intensive application for Android 2.2 and above. I know that starting
Supposing I was developing a fairly graphically intensive application (C++ or C#, graphics API
I have been developing an application for iPad that is very graphically intensive. I
I am developing the application that uses DirectX for graphics rendering. I have to
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
I am developing an application that will run on Linux to run fullscreen all
I'm developing an OpenGL application. I need to have a model of planet earth
I am developing a site which handles user input resulting in a graphical jpg

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.