package com.javapuzzlers;
import java.io.File;
public class MeToo{
public static void main(String[] args){
System.out.println(MeToo.class.getName().replaceAll("//.", File.separator) + ".class");
}
}
Solution:
显示:(在windows中)编译错误
由于File.separator的字符在windows中是“/”,而“/”有是转义字符的开始,所以程序认为println的字符串中有转移字符的存在;
TID:
When you run the program on windows, the replacement string is a lone backslash character.
Also, regular expressions are tricky: Problems tend to show up at run time rather than compile time;
Correctly:
System.out.println(MeToo.class.getName().replaceAll("//.", Matcher.quoteReplacement(File.separator)) + ".class");