2017-06-30 7 views
0
 HttpExchange exchange; 
     OutputStream responseBody = null; 
     try{ 
      File fileVal = new File(file); 
      InputStream inVal = new FileInputStream(fileVal); 
      exchange.sendResponseHeaders(HTTP_OK, fileVal.length()); 
      responseBody = exchange.getResponseBody(); 
      int read; 
      byte[] buffer = new byte[4096]; 
      while ((readVal = inVal.read(buffer)) != -1){ 
      responseBody.write(buffer, 0, readVal); 
      } 
     } catch (FileNotFoundException e){ 
      //uh-oh, the file doesn't exist 
     } catch (IOException e){ 
      //uh-oh, there was a problem reading the file or sending the response 
     } finally { 
      if (responseBody != null){ 
      responseBody.close(); 
      } 
     } 

大きなビデオファイルをチャンクとしてアップロードしようとしています。操作中に次のエラーが表示されます。FileInputStreamとFileOutputStreamを使用してファイルを大量にアップロード

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.File(org.springframework.web.multipart.commons.CommonsMultipartFile) 

これを解決するガイドがあります。

答えて

0

エラーメッセージは、エラーを完全に説明しています。タイプorg.springframework.web.multipart.commons.CommonsMultipartFileのパラメーターを受け入れるクラスFileのコンストラクターはありません。

開くファイルのパスを使用してみてください。たとえば、次のように

String path = "/path/to/your/file.txt"; 
File fileVal = new File(path); 

代わりにあなたがCommonsMultipartFileからgetInputStream()メソッドを使用することができます。ここで

InputStream inVal = file.getInputStream(); 
0
File fileVal = new File(file); 

ファイルorg.springframework.web.multipart.commons.CommonsMultipartFileタイプであり、あなたは、コンストラクタやファイルクラスにCommonsMultipartFileオブジェクトを渡すことによってFileオブジェクトを作成しようとしているCommonsMultipartFile型のコンストラクタを持っていません。

Check here for File Class Constructor

あなたはファイルオブジェクトからバイトを取得し、java.io.Fileのオブジェクトを作成する必要があります。

Convert MultiPartFile into File

関連する問題