1

in my project i am currently using direct links, these store specific files that get uploaded to the server, these locations are all in the folder of the project (fileupload)

destinationPDF=D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/
destination=D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/
fileList =D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/Directory Files/directoryFiles.txt

but this is not an ideal situation, as i am currently testing on multiple machines and each machine needs a different path, so i am wondering, is it possible to create a path so that it does not matter what machine it is on

user2065929
  • 1,065
  • 4
  • 21
  • 35
  • 1
    What happens when you save to "filename.txt" instead of hardcoding a directory? It should load/save to current directory. – NoBugs Feb 16 '13 at 23:00

1 Answers1

2

Just make it externally configurable. There are various ways to achieve that.

  1. Set an environment variable during server startup.

    SET UPLOAD_LOCATION=C:\path\to\uploads
    

    It's available as follows:

    String uploadLocation = System.getenv("UPLOAD_LOCATION");
    
  2. Set a VM argument during server startup.

    -Dupload.location="C:\path\to\uploads"
    

    It's available as follows:

    String uploadLocation = System.getProperty("upload.location");
    
  3. Set it as a properties file entry.

    upload.location=C:\path\to\uploads
    

    It's available the usual Properties API way:

    String uploadLocation = properties.getProperty("upload.location");
    

    The location of the properties file itself is actually a whole question at its own, which is already answered here: Where to place and how to read configuration resource files in servlet based application?

Either way, you can easily reference the files as follows:

File some = new File(uploadLocation, "some.ext");
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555