我想在java中的几个类之间共享一个字符串,但是字符串不是常量,所以通常的方法public static final
不起作用。
我的意思是,我更新了字符串的值,这因使用而异。
目前我使用的代码是:
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 + "/";
上面,它是通过将目标 + 用户名 + "/" 相加创建的,因此它不能是静态最终的,因为每次登录都会更改,但我仍然需要将值传递给另一个类,我该怎么做?
编辑:
我现在所做的是:
添加public static String NewDestination;
到我的 FileUploadController.java
在我的 Mybean.java 中,我添加了System.out.println(FileUploadController.NewDestination);
它,它仍然打印出 null :(