Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-platform file path building and representation

Tags:

People also ask

What is an example of a file path?

For example, if the file path is D:sources , the current directory is C:\Documents\ , and the last current directory on drive D: was D:\sources\ , the result is D:\sources\sources .

How do you write a file path?

To write a path that moves into a folder we specify the folder name, followed by a forward slash, then the file name.

What is file path in Python?

The file path is a string that represents the location of a file. It's broken up into three major parts: Folder Path: the file folder location on the file system where subsequent folders are separated by a forward slash / (Unix) or backslash \ (Windows)

What is System IO path?

Remarks. A path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk; for example, a path might map to a location in memory or on a device. The exact format of a path is determined by the current platform.


I am in a refactoring stage for a project I am working on and would like to make some improvements to how I build and represent file system paths. What things should I take into consideration when representing relative paths in Java code to ensure compatibility on Ubuntu, OSX, and Windows 7.

Currently to get an instance of File referencing "MyProject/foo/bar.f" I would have code along the lines of:

File bar = new File(ProjectDirectory + "/" + FooResourceDirectory + "/" + barName);

This seems wrong for several reasons, what are some of the best practices?