我有以下代码片段,需要一些帮助来理解其中的一些片段。
String fileName = UUID.randomUUID().toString();
int hashcode = fileName.hashCode();
//I'm not sure why we are creating a mask with an int of 255
int mask = 255;
//Wny are we adding 255 to the hashcode?
int firstDir = hashcode & mask;
//What does it mean to have (hashcode >> 8) & mask? If I were to build a third
// tier would I use (hashcode >> 16) $ mask?
int secondDir = (hashcode >> 8) & mask;
StringBuilder sb = new StringBuilder(File.separator);
//I noticed when using this %02 it truncates the directory to 2 chars, does this
//just convert 3 digits to alpha numeric representing the same three digits?
sb.append(String.format("%02x", firstDir));
sb.append(File.separator);
sb.append(String.format("%02x", secondDir));
sb.append(File.separator);
最后,如果我想从两个目录生成一个文件名,我是否只是设置另一个没有 File.separator 的字符串构建器,还是先构建没有文件分隔符的字符串,然后拆分字符串更有效?