Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 上传文件_Java_Web Services_Rest - Fatal编程技术网

Java 上传文件

Java 上传文件,java,web-services,rest,Java,Web Services,Rest,我正在尝试使用rest webservice上载文件。这是我的代码: @POST @Path(value="upload") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFile( @FormDataParam("file") InputStream fileInputStream,@FormDataParam("file") FormDataContentDisposition fileD

我正在尝试使用rest webservice上载文件。这是我的代码:

@POST
@Path(value="upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(
    @FormDataParam("file") InputStream fileInputStream,@FormDataParam("file") FormDataContentDisposition fileDetail) {
    String filePath = "C://Users/Marya/Desktop/" +fileDetail.getFileName() ;//line 28
    System.out.println("*****serverpath********");
    saveFile(fileInputStream, filePath);
    String output = "File saved to  server location : " + filePath;
    System.out.println("done");
return Response.status(200).entity(output).build();
}
我添加了必需的jar,我得到了这个错误

新错误


你的图书馆是什么?您似乎缺少jersey multipart…我添加了massing jars,现在我得到了另一个错误!!!!我编辑了我的帖子,所以你可以看到新的错误。请检查一下,没有行号就很难分辨,但我怀疑是文件详细信息为空。您确定表单参数正确吗?没错,fileDetail为null。我编辑了我的帖子,以便您可以看到获取NullPointerExceptionIs fileInputStream的行也为null?
 Grave: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
    java.lang.NullPointerException
at com.example.upload.uploadFile(upload.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)