пятница, 20 марта 2009 г.

File.separatorChar

I have just found a funny snippet in Java code:

File pom = new File(dir.getAbsoluteFile()
+ String.valueOf(File.separatorChar) + "pom.xml");


Actualy class java.io.File has two constants:
public static final char separatorChar = '\';
public static final String separator = "" + separatorChar;

This is the same symbol, but separatorChar is a char, and separator is a String.

So, instead if using String.valueOf(File.separatorChar) developer could use File.separator.

Комментариев нет:

Отправить комментарий