I would like to share a string across a couple of classes in java, however the string is not constant, so the usual method of public static final does not work.
I mean, I update the value of string, and this varies from use.
Currently the code I am using is:
public String NewDestination;
destination = "D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/Uploaded/"; // main location for uploads (CHANGE THIS WHEN USING PREDATOR)
File theFile = new File(destination + "/" + username);
theFile.mkdirs();// will create a sub folder for each user (currently does not work, below hopefully is a solution) (DOES NOW WORK)
System.out.println("Completed Creation of folder");
NewDestination = destination + username + "/";
Above, it is created from adding together destination + username + “/”, so it can not be static final as this changes on each log in, but I still need the value passed to another class, how can I do this ?
EDIT:
What I have now done is:
added public static String NewDestination; to my FileUploadController.java
and in my Mybean.java I added System.out.println(FileUploadController.NewDestination); and it still out prints null 🙁
It sounds like you want a
public staticnon-finalfield.However, this would allow other classes to change it too.
It would be better to make a
private staticfield, and apublic static getDestination()method to allow other classes to read it.