ABSTRACT

The use of hardcoded file separators causes portability problems.

EXPLANATION

Different operating systems use different characters as file separators. For example, Microsoft Windows systems use "\", while UNIX systems use "/". When applications have to run on different platforms, the use of hardcoded file separators can lead to incorrect execution of application logic and potentially a denial of service.



Example 1: The following code uses a hardcoded file separator to open a file:


...
File file = new File(directoryName + "\\" + fileName);
...

REFERENCES

[1] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 474