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();
}
}
我正在尝试以块的形式上传大型视频文件。在执行该操作时,出现以下错误。 groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.io.File(org.springframework.web.multipart.commons.CommonsMultipartFile)
任何人指导我解决这个问题。
最佳答案
File fileVal = new File(file);
这里的文件是org.springframework.web.multipart.commons.CommonsMultipartFile类型,并且您试图通过在构造函数中传递CommonsMultipartFile对象来创建File对象,并且File类没有CommonsMultipartFile类型的构造函数。
Check here for File Class Constructor
您需要从文件对象获取字节并创建一个java.io.File对象。
Convert MultiPartFile into File
关于java - 使用FileInputStream和FileOutputStream上传大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44845351/