Sunday, 25 June 2017

Get File Separator in Java ~ foundjava

An example on getting file separator thereby detecting the OS approximately. Single statement.

File Separator Example


import java.io.*;
class GetFileSeparator
{
 public static void main(String args[])
 {
 System.out.println("The file separator is "+File.separatorChar);
 }
}

Sample Output


The file separator is \

Note: The file separator depends upon your OS. If windows the above is the output, for linux like OS / is the file separator.

No comments:

Post a Comment