0
我有一個應該爲程序提供路徑的類。爲了做到這一點,它決定了Windows下的本地和漫遊數據路徑,並在Linux下取得了一個家目錄。除此之外,它提供了來自其他路徑的路徑。一類中靜態初始值設定項的初始化順序
它是安全的寫
public class DataDirectory {
public static final File ROAMING;
public static final File LOCAL;
static {
// set ROAMING and LOCAL
}
public static final File PROFILE = doMkdirs(new File(ROAMING, "profiles");
public static final File SETUP = doMkdirs(new File(ROAMING, "setup");
public static final File LOGFILES = doMkdirs(new File(ROAMING, "logfiles");
private static File doMkdirs(File file) {
file.mkdirs();
return file;
}
}
或做我必須做的
public class DataDirectory {
public static final File ROAMING;
public static final File LOCAL;
public static final File PROFILE;
public static final File SETUP;
public static final File LOGFILES;
static {
// set ROAMING and LOCAL
PROFILE = mkdirsRoaming("profiles");
SETUP = mkdirsRoaming("setup");
LOGFILES = mkdirsRoaming("logfiles");
}
public static final File PROFILE = doMkdirs(new File(ROAMING, "profiles");
public static final File SETUP = doMkdirs(new File(ROAMING, "setup");
public static final File LOGFILES = doMkdirs(new File(ROAMING, "logfiles");
private static File doMkdirs(File file) {
file.mkdirs();
return file;
}
}
上爲了安全嗎?