0
点赞
收藏
分享

微信扫一扫

关于:File.separator

其实 File.separator 的作用相当于 ' \  '

在 windows 中 文件文件分隔符 用 ' \ ' 或者 ' / ' 都可以

但是在 Linux 中,是不识别 ' \ ' 的,而 File.separator 是系统默认的文件分隔符号,在 UNIX 系统上,此字段的值为 ' / '

在 Microsoft Windows 系统上,它为 ' \ ' 屏蔽了这些系统的区别。

所以用 File.separator 保证了在任何系统下不会出错。

  protected String path;

public static String PATH_SEPERATOR = "/";

static {
String property = System.getProperties().getProperty("file.separator");
if (property != null) {
PATH_SEPERATOR = property;
}
}

public void setPath(String path) {
if (!path.endsWith(PATH_SEPERATOR)) {
path += PATH_SEPERATOR;
}
this.path = path;
}

作者:三号小玩家


举报

相关推荐

0 条评论