Skip to Content

Get file separator using System class

  1. /*
  2.         Get file separator using System class
  3.         This example shows how to get the file separator using
  4.         System class.
  5. */
  6.  
  7.  
  8. public class GetFileSeparator {
  9.  
  10.         public static void main(String[] args) {
  11.                
  12.                 /*
  13.                  * Get file.separator system property using
  14.                  * public static String getProperty(String name) method of
  15.                  * System class.
  16.                  */
  17.                
  18.                 String strFileSeparator = System.getProperty("file.separator");
  19.                
  20.                 System.out.println("File separator is : " + strFileSeparator);
  21.         }
  22. }
  23.  
  24. /*
  25. Output would be system dependent. Typical output would be
  26. File separator is : \
  27. */