大家好,我有一个问题,我有一个属性文件,它存储了所有的保存位置,我通过以下方式从这个文件中获取数据:
public void loadProp() {
System.out.println("Loading properties");
InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.properties"); //points to a properties file, this will load up destinations instead of having to declare them here
try {
configProp.load(in);
System.out.println(configProp.getProperty("destinationPDF"));
System.out.println(configProp.getProperty("destination"));
System.out.println(configProp.getProperty("fileList"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("called get username");
username = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
System.out.println(username);
}
然后我这样做以将值分配给目标
public String destination = configProp.getProperty("destination");
但是每当我使用目的地时,我都会得到一个空值,但是如果我使用 configProp.getProperty("destination") 我会得到完整的路径,我在这里做错了什么,因为我希望该值指向目的地,因为其他类取决于它
编辑 :
This class is called on by a command button (web app)
@ViewScoped
@ManagedBean(name = "fileUploadController")
public class FileUploadController {
public boolean isUploadComplete() { //to enable the next button once finished
return uploadComplete;
}
public void setUploadComplete(boolean uploadComplete) {
this.uploadComplete = uploadComplete;
}
public boolean isUploadComplete2() {
//to disable the file upload button, this will stop users uploading multiple files and over writing them as only the last file uploaded will be used
return uploadComplete;
}
public void setUploadComplete2(boolean uploadComplete) {
this.uploadComplete = uploadComplete;
}
/*
public void handleFileUpload(FileUploadEvent event) {
System.out.println("called");
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
*/
//
//Strings for fileUpload
//oadProp()
//public String fileList = "D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/Directory Files/directoryFiles.txt"; //
private Properties configProp = new Properties();
@PostConstruct
//System.out.println(destinationPDF);
//System.out.println(destination);
// Get the username from the login page, this is used to create a folder for each user
public void loadProp() {
System.out.println("Loading properties");
InputStream in = this.getClass().getClassLoader().getResourceAsStream("config.properties"); //points to a properties file, this will load up destinations instead of having to declare them here
try {
configProp.load(in);
System.out.println(configProp.getProperty("destinationPDF"));
System.out.println(configProp.getProperty("destination"));
System.out.println(configProp.getProperty("fileList"));
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("called get username");
username = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
System.out.println(username);
}
//String destinationPDF = configProp.getProperty("destinationPDF"); Always makes a null no idea why yet
//private String destinationPDF = configProp.getProperty("destinationPDF");
public String destination = configProp.getProperty("destination");
private String username;
//public static String destination = "D:/Documents/NetBeansProjects/printing~subversion/fileupload/uploaded/"; // main location for uploads//TORNADO ONLY //"D:/My Documents/NetBeansProjects/printing~subversion/fileupload/uploaded/"; // USE ON PREDATOR ONLY
public static String NewDestination;
public static String UploadedfileName;
public static String CompletefileName;
//
//Strings for file copy
//
//private String destinationPDF = "D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/"; //USE ON TORNADO//"D:/My Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/";//USE ON PREDATOR
private String NewdestinationPDF;
public static String PdfLocationViewable;
private boolean uploadComplete;
private boolean uploadComplete2;
//
public void File() {
以上是该类的第一段代码
控制台中的输出是:
INFO: buttonToUploadText invoked
INFO: Loading properties
INFO: D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/pdf/
INFO: D:/Documents/NetBeansProjects/printing~subversion/fileupload/Uploaded/
INFO: D:/Documents/NetBeansProjects/printing~subversion/fileupload/web/resources/Directory Files/directoryFiles.txt
INFO: called get username
INFO: null
INFO: destination is null