java长传问题,输入输出流
java.lang.NullPointerException
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at com.mengfang.action.FileUploadAction.execute(FileUploadAction.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
后台是这样的
String path = ServletActionContext.getRequest().getRealPath("/assignFile");
try {
File f = this.getFile();
FileInputStream inputStream = new FileInputStream(f);
FileOutputStream outputStream = new FileOutputStream(path + "/"+ this.getFileFileName());
byte[] buf = new byte[1024];
int length = 0;
while ((length = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, length);
}
inputStream.close();
outputStream.flush();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(path);
return "success";
[解决办法]
File f = this.getFile();
f 返回的是null
[解决办法]
this.getFile()为null,所以获取该文件的输入流的时候空指针异常
[解决办法]
正解!!!!