私が作成したコードが、相互に複数のディレクトリを作成するために機能するかどうか疑問に思っていました。これを参考にしました。
String username = enterUserTF.getText(); //the username the user enters in a textfield.
boolean myGamesFolderSuccess = new File(System.getProperty("user.home"), "My Games").mkdir();
boolean mainFolderSuccess = new File("My Games", "Type King").mkdir();
boolean userSuccess = new File("TypeKing", username).mkdir(); //creates a folder with the users username.
if(myGamesFolderSuccess){
if(mainFolderSuccess){
if(userSuccess){
System.out.println("Directory " + username + " created.");
File f = new File(username + "/test.txt");
if(!f.exists()){
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
System.out.println("Could not create user's file.");
}
}
}
}
}
}
したがって、上記を要約すると、最初のディレクトリ「My Games」を作成し、そのディレクトリuser.home
にゲームの名前「Type King」を配置し、ユーザーがユーザー名を入力するたびに、次のようなディレクトリを作成する必要があります。彼らのユーザー名。 File f
ディレクトリ内のファイルをチェックするだけですusername
。