Fix crash when unexisting subdir

This commit is contained in:
Louis Royer 2020-03-04 15:14:18 +01:00
parent 5a54663a7a
commit 600ef1b2cd
2 changed files with 15 additions and 0 deletions

View File

@ -13,6 +13,7 @@ public class ServerP2P {
public ServerP2P() {
directories = new Directories("P2P_JAVA_PROJECT_SERVER");
directories.createSubdir(subdir);
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
port = 40001;
System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory() + subdir);

View File

@ -48,6 +48,20 @@ public class Directories {
new File(dataHomeDirectory).mkdirs();
}
/** Create a subdirectory.
* @param subdir Name of subdirectory to create
*/
public void createSubdir(String subdir) {
String d = dataHomeDirectory;
if (subdir != null) {
d += subdir;
if (!subdir.endsWith("/")) {
d += "/";
}
}
new File(d).mkdirs();
}
/** Getter for dataHomeDirectory.
* @return path to the application home directory
*/