Java programmers knows about methods quoted in title, but many doesn’t care with them.
These methods are useful for programmer that do not knows wich characters represents file separator and path separator at OS that supports your application.
Linux/Unix, the methods File.separator and File.pathSeparator returns “/” and “.”, while in Windows, these methods returns “\” (or “\\” – escape) and “;”.
In recent case, the code below threw exception FileNotFoundException running over Linux, but not running over Windows:
String appPath = ctx.getRealPath(); String filePath = appPath + "\\" + "WEB-INF/classes/my/application/packages/"; File file = new File(filePath, "report.pdf"); OutputStream out = new FileOutputStream(file); ...
Worked in both systems after to replace “\\” by File.separator in line 2:
String appPath = ctx.getRealPath(); String filePath = appPath + File.separator + "WEB-INF/classes/my/application/packages/"; File file = new File(filePath, "report.pdf"); OutputStream out = new FileOutputStream(file); ...
Utilization of these methods, besides a good practice, is very usefull when same version of an application is running over differents operacional systems.

