我正在使用Primefaces将图像上传到tomcat
通过<p:fileUpload/>
我正在此文件夹中上传:C:\NEW WORK\sicweb\src\main\webapp\resources\images
但是当我把我的应用程序放在服务器上时,我不能这样说。如何通过相对路径或类似的东西选择文件夹
或者放在C:\java\apache-tomcat-8.0.32\webapps\sicweb
里面?
这是我的班级:
public class UploadLogoOrgaoControle implements Serializable {
public static String name = "";
private String caminhoCarregado = "";
private static final long serialVersionUID = 1L;
public void handleFileUpload(FileUploadEvent event) throws IOException {
String path = "C:\\NEW WORK\\sicweb\\src\\main\\webapp\\resources\\images\\";
name = event.getFile().getFileName();
File file = new File(path + name);
caminhoCarregado = "/sicweb/resources/images/" + name;
InputStream is = event.getFile().getInputstream();
OutputStream out = new FileOutputStream(file);
byte buf[] = new byte[1024];
int len;
while ((len = is.read(buf)) > 0)
out.write(buf, 0, len);
is.close();
out.close();
}
public String getCaminhoCarregado() {
return caminhoCarregado;
}
public void setCaminhoCarregado(String caminhoCarregado) {
this.caminhoCarregado = caminhoCarregado;
}
}