java.lang.NullPointerException
at java.io.File.<init>(File.java:194)
at com.yourcompany.struts.untils.ConfigManager.<clinit>(ConfigManager.java:17)
at com.yourcompany.struts.action.FileAction.execute(FileAction.java:55)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
先粘一段错误信息、我是通过写一个静态代码块获取properties文件 里面的储存路径、
ConfigManager里面的静态代码
static{
Properties config = new Properties();
try {
InputStream configStream=ConfigManager.class.getResourceAsStream("/path.properties");
config.load(configStream);
saveDir = config.getProperty("saveDir");
configStream.close();
File file = new File(saveDir);
if(!file.exists()){
file.mkdirs();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}------------------------------下面是action里面的处理
FileForm fileForm = (FileForm) form;
response.setContentType("text/html;charset=GBK");
FormFile photo =fileForm.getUser().getPhoto();
InputStream contentStream = photo.getInputStream();
String fileName=photo.getFileName();
if(!(fileName.trim().equals("")||photo.getFileSize()==0)){
String saveDir=ConfigManager.getSaveDir();
File file = new File(saveDir,fileName);
FileOutputStream fos = new FileOutputStream(file);
int len=0;
byte [] content = new byte[1024];
while((len=contentStream.read(content))!=-1){
fos.write(content, 0, len);
}

contentStream.close();
fos.close();

}
-------------------------------------还有一个问题、属性文件怎么设置路径、使其储存的路径以改项目为根目录?? 小菜在这提前写过  各位高手了、、多多指点

解决方案 »

  1.   

    你form贴出来,速度,我要去看球了!有没有enctype="multipart/form-data"
      

  2.   

      <body>
     <html:form action="fileAction" enctype="multipart/form-data">
        <html:file property="user.photo"></html:file>
        <html:submit></html:submit>
    </html:form>
      </body>
      

  3.   

     好像是好了 是tomcat的问题、 现在主要的问题是、怎么设置路径、是相对改项目的、我的属性文件写的是 绝对的 路径D:/xxxxxx
      

  4.   

    request.getRealPath("/") + 相对路径