Fix crash when unexisting subdir
This commit is contained in:
parent
5a54663a7a
commit
600ef1b2cd
@ -13,6 +13,7 @@ public class ServerP2P {
|
|||||||
|
|
||||||
public ServerP2P() {
|
public ServerP2P() {
|
||||||
directories = new Directories("P2P_JAVA_PROJECT_SERVER");
|
directories = new Directories("P2P_JAVA_PROJECT_SERVER");
|
||||||
|
directories.createSubdir(subdir);
|
||||||
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
||||||
port = 40001;
|
port = 40001;
|
||||||
System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
System.out.println("Server will listen on port " + port + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
||||||
|
@ -48,6 +48,20 @@ public class Directories {
|
|||||||
new File(dataHomeDirectory).mkdirs();
|
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.
|
/** Getter for dataHomeDirectory.
|
||||||
* @return path to the application home directory
|
* @return path to the application home directory
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user