Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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 如何从vertx中的文件中获取字节[]_Java_Arrays_File Upload_Byte_Vert.x - Fatal编程技术网

Java 如何从vertx中的文件中获取字节[]

Java 如何从vertx中的文件中获取字节[],java,arrays,file-upload,byte,vert.x,Java,Arrays,File Upload,Byte,Vert.x,我正试图从一个文件中提取字节[],我将在post调用中接收该文件的表单数据。但是,我没有找到任何有用的代码片段来帮助我获取字节[]。下面是我正在尝试的代码 public static void main( String[] args ) { Vertx vertx =Vertx.vertx(); HttpServer httpServer= vertx.createHttpServer() ; Router router=Router.route

我正试图从一个文件中提取字节[],我将在post调用中接收该文件的表单数据。但是,我没有找到任何有用的代码片段来帮助我获取字节[]。下面是我正在尝试的代码

public static void main( String[] args )
{
        Vertx vertx =Vertx.vertx();
        HttpServer httpServer= vertx.createHttpServer() ;

        Router router=Router.router(vertx);
router.route().handler(BodyHandler.create().setUploadsDirectory("uploads"));

 router.post("/form").handler(ctx -> {
           ctx.response().putHeader("Content-Type", "text/plain");

            ctx.response().setChunked(true);
            MultiMap attributes = ctx.request().formAttributes();
            Set<io.vertx.ext.web.FileUpload> uploads = ctx.fileUploads();
            ctx.response().end();
      }

  httpServer
     .requestHandler(router::accept)
     .listen(8091);
    } 
publicstaticvoidmain(字符串[]args)
{
Vertx Vertx=Vertx.Vertx();
HttpServer HttpServer=vertx.createHttpServer();
路由器=路由器。路由器(vertx);
router.route().handler(BodyHandler.create().setUploadsDirectory(“上载”));
router.post(“/form”).handler(ctx->{
ctx.response().putHeader(“内容类型”、“文本/普通”);
ctx.response().setChunked(true);
MultiMap attributes=ctx.request().formAttributes();
设置uploads=ctx.fileUploads();
ctx.response().end();
}
httpServer
.requestHandler(路由器::接受)
.听(8091);
} 
在这里,文件被上传到服务器的uploads文件夹中。但是,我不想在服务器上上传文件,而是希望文件的字节[]传输到不同的服务进行上传。因此,如果我评论这一行 router.route().handler(BodyHandler.create().setUploadsDirectory(“上载”));
文件未上载到系统。因此,如果我未在服务器上上载文件,现在有人能告诉我如何获取文件的字节[]。

文件上载对象为您提供上载文件的路径。您可以使用Vert.x
文件系统
API加载其内容:

vertx.fileSystem().readFile(fileUpload.uploadedFileName(), ar -> {
  if (ar.succeeded()) {
    byte[] content = ar.result().getBytes();
    // use the content
  } else {
    // deal with failure
  }
});

您好,我不想在服务器上上传文件,而是想将文件字节[]传递给一个单独的服务。因此,如果您能让我在不上传到服务器上的情况下获取字节,那就太好了!!那么您想要的实际上是在发送前加载内容的客户端代码?